local w=script.Parent local G=w.JackpotValues local y=w.Lights local g=w.Lights2 local N=w.TicketValues local n=w.Arm local I=w.StopButton local J=false local o={5;4;3,1,2,3,4,5,5,4;3;1;2,3;4,5}local s={6;5,5,4;4,3;3;1;1;2;2;3;3;4,4;5;5;6;5;5,4,4,3,3,1;1,2;2,3;3,4,4;5,5}local Q=false local x=1 wait()w.CreditsDisp.Value.Value=0 for w,G in pairs(G:GetChildren())do G.SurfaceGui.TextLabel.Text=values[6]end for w=1,16,1 do N[tostring(w)].SurfaceGui.TextLabel.Text=values[o[w]]end function start()w.CreditsDisp.Value.Value=w.Credits.Value if not Q and w.Credits.Value>0 then Q=true J=false n.ClickDetector.MaxActivationDistance=10 w.Timer.Value.Value=20 w.Timer.Disabled=false end end function clickArm(G)if G==1 or G.Name==w.CardReader.GameInfo.Player.Value then J=true I.LeverPull.TimePosition=1 I.LeverPull:Play()w.Timer.Disabled=true w.Timer.Value.Value=0 n.ClickDetector.MaxActivationDistance=0 n.HingeConstraint.TargetAngle=50 wait(.5)n.HingeConstraint.TargetAngle=0 wait(.5)for w,G in pairs(w.Lights3:GetChildren())do G.Material=Enum.Material.Neon end I.Click:Play()I.Material=Enum.Material.Neon w.Timer.Value.Value=20 w.Timer.Disabled=false x=0 repeat x=x+1 if x==35 then x=1 end y[tostring(x)].Material=Enum.Material.Neon wait(wheelSpeed)if I.Material==Enum.Material.Neon then y[tostring(x)].Material=Enum.Material.SmoothPlastic end until I.Material==Enum.Material.SmoothPlastic end end function clickButton(G)if I.Material==Enum.Material.Neon and(G==1 or G.Name==w.CardReader.GameInfo.Player.Value)then I.Click:Stop()w.Timer.Disabled=true w.Timer.Value.Value=0 I.Material=Enum.Material.SmoothPlastic for w,G in pairs(w.Lights3:GetChildren())do G.Material=Enum.Material.SmoothPlastic end if s[x]==6 then local w=math.random(1,jpChance)if w~=1 then y[tostring(x)].Material=Enum.Material.SmoothPlastic x=x+1 end end ticketOut(values[s[x]])if s[x]==6 then I.Bell:Play()I.JPMusic.TimePosition=.5 I.JPMusic:Play()for w=1,12,1 do y[tostring(x)].Material=Enum.Material.Neon wait(.5)for w,G in pairs(y:GetChildren())do G.Material=Enum.Material.Neon end for w,G in pairs(g:GetChildren())do G.Material=Enum.Material.SmoothPlastic end wait(.5)for w,G in pairs(y:GetChildren())do G.Material=Enum.Material.SmoothPlastic end for w,G in pairs(g:GetChildren())do G.Material=Enum.Material.Neon end end for w,G in pairs(g:GetChildren())do G.Material=Enum.Material.SmoothPlastic end I.JPMusic:Stop()else I.Win:Play()for w=1,8,1 do y[tostring(x)].Material=Enum.Material.Neon wait(.5)y[tostring(x)].Material=Enum.Material.SmoothPlastic wait(.5)end end Q=false w.Credits.Value=w.Credits.Value-1 end end w.Timer.Changed:connect(function()if w.Timer.Value.Value==0 and not w.Timer.Disabled then if J then clickButton(1)else clickArm(1)end end end)n.ClickDetector.MouseClick:connect(clickArm)I.ClickDetector.MouseClick:connect(clickButton)w.Credits.Changed:connect(start)function ticketOut(G)w.CardReader.GameInfo.TicketsWon.Value=w.CardReader.GameInfo.TicketsWon.Value+G end
-- OBJECT DIRECTORY
local machine = script.Parent
local jackpotValues = machine.JackpotValues
local lights = machine.Lights
local lights2 = machine.Lights2
local ticketValues = machine.TicketValues
local arm = machine.Arm
local button = machine.StopButton
local isSpinning = false
local zone = { 5, 4, 3, 1, 2, 3, 4, 5, 5, 4, 3, 1, 2, 3, 4, 5 }
local lzone = { 6, 5, 5, 4, 4, 3, 3, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 5, 5, 4, 4, 3, 3, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 }
local active = false
local index = 1

wait()
machine.CreditsDisp.Value.Value = 0
for _, a in pairs(jackpotValues:GetChildren()) do
	a.SurfaceGui.TextLabel.Text = values[6]
end
for i = 1, 16 do
	ticketValues[tostring(i)].SurfaceGui.TextLabel.Text = values[zone[i]]
end

function start()
	machine.CreditsDisp.Value.Value = machine.Credits.Value
	if not active and machine.Credits.Value > 0 then
		active = true
		isSpinning = false
		arm.ClickDetector.MaxActivationDistance = 10
		machine.Timer.Value.Value = 20
		machine.Timer.Disabled = false
	end
end

function clickArm(plr)
	if plr == 1 or plr.Name == machine.CardReader.GameInfo.Player.Value then
		isSpinning = true
		button.LeverPull.TimePosition = 1
		button.LeverPull:Play()
		machine.Timer.Disabled = true
		machine.Timer.Value.Value = 0
		arm.ClickDetector.MaxActivationDistance = 0
		arm.HingeConstraint.TargetAngle = 50
		wait(0.5)
		arm.HingeConstraint.TargetAngle = 0
		wait(0.5)
		for _, a in pairs(machine.Lights3:GetChildren()) do
			a.Material = Enum.Material.Neon
		end
		button.Click:Play()
		button.Material = Enum.Material.Neon
		machine.Timer.Value.Value = 20
		machine.Timer.Disabled = false
		index = 0
		repeat
			index = index + 1
			if index == 35 then
				index = 1
			end
			lights[tostring(index)].Material = Enum.Material.Neon
			wait(wheelSpeed)
			if button.Material == Enum.Material.Neon then
				lights[tostring(index)].Material = Enum.Material.SmoothPlastic
			end
		until button.Material == Enum.Material.SmoothPlastic
	end
end

function clickButton(plr)
	if button.Material == Enum.Material.Neon and (plr == 1 or plr.Name == machine.CardReader.GameInfo.Player.Value) then
		button.Click:Stop()
		machine.Timer.Disabled = true
		machine.Timer.Value.Value = 0
		button.Material = Enum.Material.SmoothPlastic
		for _, a in pairs(machine.Lights3:GetChildren()) do
			a.Material = Enum.Material.SmoothPlastic
		end
		if lzone[index] == 6 then
			local r = math.random(1, jpChance)
			if r ~= 1 then
				lights[tostring(index)].Material = Enum.Material.SmoothPlastic
				index = index + 1
			end
		end
		ticketOut(values[lzone[index]])
		if lzone[index] == 6 then
			button.Bell:Play()
			button.JPMusic.TimePosition = 0.5
			button.JPMusic:Play()
			for i = 1, 12 do
				lights[tostring(index)].Material = Enum.Material.Neon
				wait(0.5)
				for _, a in pairs(lights:GetChildren()) do
					a.Material = Enum.Material.Neon
				end
				for _, a in pairs(lights2:GetChildren()) do
					a.Material = Enum.Material.SmoothPlastic
				end
				wait(0.5)
				for _, a in pairs(lights:GetChildren()) do
					a.Material = Enum.Material.SmoothPlastic
				end
				for _, a in pairs(lights2:GetChildren()) do
					a.Material = Enum.Material.Neon
				end
			end
			for _, a in pairs(lights2:GetChildren()) do
				a.Material = Enum.Material.SmoothPlastic
			end
			button.JPMusic:Stop()
		else
			button.Win:Play()
			for i = 1, 8 do
				lights[tostring(index)].Material = Enum.Material.Neon
				wait(0.5)
				lights[tostring(index)].Material = Enum.Material.SmoothPlastic
				wait(0.5)
			end
		end
		active = false
		machine.Credits.Value = machine.Credits.Value - 1
	end
end

machine.Timer.Changed:connect(function()
	if machine.Timer.Value.Value == 0 and not machine.Timer.Disabled then
		if isSpinning then
			clickButton(1)
		else
			clickArm(1)
		end
	end
end)

arm.ClickDetector.MouseClick:connect(clickArm)
button.ClickDetector.MouseClick:connect(clickButton)
machine.Credits.Changed:connect(start)
function ticketOut(tix)
	machine.CardReader.GameInfo.TicketsWon.Value = machine.CardReader.GameInfo.TicketsWon.Value + tix
end
