so i have this code for a toggle switch in a ui
if state then local Object = game:GetService("Workspace")[".Spawns"][".Orbs"].Orb while wait() do game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = Object.CFrame end else end end)
the if state then code runs if the toggle switch is set to true, i made it so that orbs spawn randomly in my game and there is a toggle switch that is meant to collect them all for you and it works except toggling it off does nothing and it tps only once then spam tps you to the spot where the original orb was, it doesnt tp to the ones that spawn after.. if anyone would help me with this id be really thankful, also sorry for any mistakes im new to the site