local number = 1 local clickDetector = script.Parent clickDetector.MouseClick:Connect(function() local wChildren = game:GetService("Workspace"):GetChildren() for i,c in pairs(wChildren) do if string.sub(c.Name, 1, 2) == "FM" then c.Parent = game.Lighting local fm = 'FM'..number if game:GetService("Lighting"):FindFirstChild(fm) then local fm1 = game:GetService("Lighting"):FindFirstChild(fm) fm1.Parent = game:GetService("Workspace") print(fm) number = number + 1 else local number = 1 print('FM'..number) end end end end)
the problem is that it won't continue with the if loop, it just stops in the else statement, but I want it to go with the loop
this is the entire output
FM1
FM2
FM3
FM4
FM5
FM6
FM7
FM8
FM9
FM1
why doesnt it go back to FM1 and then loop the output again?
As far as I can tell, there is nothing wrong with your script apart from line 18 where you said local number = 1. Presumably you would go from 1 - 9 and subsequently be stuck there? Im gonna include an example for cycling through a list anyways(place in a part btw):
local part = script.Parent local n = 0 local clickD = Instance.new("ClickDetector", part) local list = {"fm1","fm2","fm3","fm4","fm5","fm6","fm7","fm8","fm9"} -- hyperrealistic replica of sounds clickD.MouseClick:Connect(function() if n < 9 then n = n + 1 else n = 1 end print(list[n]) end)