While loop running twice per iteration

(local script stored in playercharacterscripts) while loop firing twice per iteration when it shouldnt be, what is going on?

local RS = game:GetService("ReplicatedStorage")
local Spawners =game.Workspace.MobSpawners:GetChildren()
print("number of spawners =", #Spawners)

local l = 1
while true do
	task.wait(1)
	for I,SpawnFolder in pairs(Spawners) do
		print(l)
		l+=1
	end
end

output:

Kind of looks like you have a duplicate script. Maybe try to verify you don’t have a copy hiding somewhere.

Try searching for ‘ActivateSpawners’ above the explorer tab.

1 Like

Just curios, is this possibly running once in the PlayerCharacterScripts folder, and then also in the player’s character once cloned?

if (game.Players.LocalPlayer.Character == script.Parent) then
	local RS = game:GetService("ReplicatedStorage")
	local Spawners =game.Workspace.MobSpawners:GetChildren()
	print("number of spawners =", #Spawners)

	local l = 1
	while true do
		task.wait(1)
		for I,SpawnFolder in pairs(Spawners) do
			print(l)
			l+=1
		end
	end
end
1 Like

you where right it was getting cloned the reason it was difficult to find was because it was cloning into a viewport frame so struggled to find it, anyway cheers

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.