Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago

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
0
Does it return an error? I'm going to review your code. HaloUlti 63 — 5y
0
Nothing on output AvionicScript 65 — 5y
0
Is it at the start of the script? If it is, there will be no players when the script first runs. mattscy 3725 — 5y
0
No it has 3 waits of 5 seconds each before it reaches the loop. AvionicScript 65 — 5y
0
I feel like you are not suppporting both R15 and R6 rigs. Use HumanoidRootPart instead of Torso since Torso is only at R6. Bilinearly 58 — 5y

1 answer

Log in to vote
0
Answered by
CPF2 406 Moderation Voter
5 years ago
Edited 5 years ago

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
Ad

Answer this question