Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

For loop not doing anything, not even prints. What did I do wrong?

Hello,

This for loop is not working, it doesn't even print anything.

Why isn't it working? If it's not the correct method then what do I need to do? FireAllClients and use a local script?

local plrs = game.Players:GetPlayers() -- Also tried :GetChildren()

for i,v in pairs(plrs) do
	local Spawn = game.Workspace[currentMap.Name].Spawn
	print(currentMap.Name)
	v.Character.Torso.CFrame = CFrame.new(Spawn.Position)
	Spawn:Destroy()
	v.Character.Humanoid.Walkspeed = 0
	wait()
	print(v.Name)
end

I also tried the

for i = 1,#plrs do
	local Spawn = game.Workspace[currentMap.Name].Spawn
	print(currentMap.Name)
	plrs[i].Character.Torso.CFrame = CFrame.new(Spawn.Position)
	Spawn:Destroy()
	plrs[i].Character.Humanoid.Walkspeed = 0
	wait()
	print(v.Name)
end

5 comments

0

Does it return an error? I'm going to review your code.

0

Nothing on output

0

Is it at the start of the script? If it is, there will be no players when the script first runs.

0

No it has 3 waits of 5 seconds each before it reaches the loop.

0

I feel like you are not suppporting both R15 and R6 rigs. Use HumanoidRootPart instead of Torso since Torso is only at R6.

1 answer

✓ Accepted answer

I'm not really quite sure why it doesn't work, but I'll provide a script that I think will work.

for i,v in pairs(game:GetService('Players'):GetChildren()) do

    local Spawn = game.Workspace:FindFirstChild(currentMap.Name):FindFirstChild('Spawn')
    local Character = v.Character or v.CharacterAdded:Wait()

    print(currentMap.Name)

    Character:FindFirstChild('HumanoidRootPart').CFrame = CFrame.new(Spawn.Position)

    Spawn:Destroy()

    Character:FindFirstChildOfClass('Humanoid').Walkspeed = 0

    wait()
    print(v.Name)

end

This discussion is preserved as it was. New answers, comments, and votes are closed.