local W=script.Parent local Q=W.JackpotValues local i=W.Lights local f=W.Lights2 local F=W.TicketValues local N=W.Arm local y=W.StopButton local p=false local H={5,4;3,1;2,3,4;5;5,4,3;1;2,3,4;5}local e={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 V=false local L=1 wait()W.CreditsDisp.Value.Value=0 for W,Q in pairs(Q:GetChildren())do Q.SurfaceGui.TextLabel.Text=values[6]end for W=1,16,1 do F[tostring(W)].SurfaceGui.TextLabel.Text=values[H[W]]end function start()W.CreditsDisp.Value.Value=W.Credits.Value if not V and W.Credits.Value>0 then V=true p=false N.ClickDetector.MaxActivationDistance=10 W.Timer.Value.Value=20 W.Timer.Disabled=false end end function clickArm(Q)if Q==1 or Q.Name==W.CardReader.GameInfo.Player.Value then p=true y.LeverPull.TimePosition=1 y.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,Q in pairs(W.Lights3:GetChildren())do Q.Material=Enum.Material.Neon end y.Click:Play()y.Material=Enum.Material.Neon W.Timer.Value.Value=20 W.Timer.Disabled=false L=0 repeat L=L+1 if L==35 then L=1 end i[tostring(L)].Material=Enum.Material.Neon wait(wheelSpeed)if y.Material==Enum.Material.Neon then i[tostring(L)].Material=Enum.Material.SmoothPlastic end until y.Material==Enum.Material.SmoothPlastic end end function clickButton(Q)if y.Material==Enum.Material.Neon and(Q==1 or Q.Name==W.CardReader.GameInfo.Player.Value)then y.Click:Stop()W.Timer.Disabled=true W.Timer.Value.Value=0 y.Material=Enum.Material.SmoothPlastic for W,Q in pairs(W.Lights3:GetChildren())do Q.Material=Enum.Material.SmoothPlastic end if e[L]==6 then local W=math.random(1,jpChance)if W~=1 then i[tostring(L)].Material=Enum.Material.SmoothPlastic L=L+1 end end ticketOut(values[e[L]])if e[L]==6 then y.Bell:Play()y.JPMusic.TimePosition=.5 y.JPMusic:Play()for W=1,12,1 do i[tostring(L)].Material=Enum.Material.Neon wait(.5)for W,Q in pairs(i:GetChildren())do Q.Material=Enum.Material.Neon end for W,Q in pairs(f:GetChildren())do Q.Material=Enum.Material.SmoothPlastic end wait(.5)for W,Q in pairs(i:GetChildren())do Q.Material=Enum.Material.SmoothPlastic end for W,Q in pairs(f:GetChildren())do Q.Material=Enum.Material.Neon end end for W,Q in pairs(f:GetChildren())do Q.Material=Enum.Material.SmoothPlastic end y.JPMusic:Stop()else y.Win:Play()for W=1,8,1 do i[tostring(L)].Material=Enum.Material.Neon wait(.5)i[tostring(L)].Material=Enum.Material.SmoothPlastic wait(.5)end end V=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 p then clickButton(1)else clickArm(1)end end end)N.ClickDetector.MouseClick:connect(clickArm)y.ClickDetector.MouseClick:connect(clickButton)W.Credits.Changed:connect(start)function ticketOut(Q)W.CardReader.GameInfo.TicketsWon.Value=W.CardReader.GameInfo.TicketsWon.Value+Q end

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(.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(.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
