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

looping script not running :moveto() for player?

Asked by 7 years ago

the intended use of this script is so when ever the script cycles through, it will move all the players to there respective spawn point. (there are 8, all numbered 1 - 8). the problem is that it does not move the player and does not give out any errors. [Filtering Enabled is active]

local GameTime = 5
local InterTime = 5
players = game.Players:GetChildren()
while wait() do
    if game.Players.NumPlayers >= 2 then
        for i = 0,InterTime,1 do
            wait(1)
            print(i)
        end
        lastusedpoint = 0 
        for i,player in pairs(players) do
        if player.Character ~= nil then
            lastusedpoint = lastusedpoint + 1
            player.Character:MoveTo(workspace.Points:GetChildren()[lastusedpoint].Position)
        end
        end
        wait(GameTime)
    else
    end
end
0
Local script? FE Is enabled so you might have to do it by the server. Abstract_Life 65 — 7y
0
not a localscript pluginfactory 463 — 7y

1 answer

Log in to vote
0
Answered by
soved 69
7 years ago

OK, so this is what you did wrong:

-- Line 3
players = game.Players:GetChildren() 

Your code seems harmless, doesn't it? But that line of code gets all of the Players who are in the Game at that specific time. Which means it doesn't get updated! That's why your If statement at line 5 never happens.

No worries, we can easily fix this by doing this:

-- Change line 11 with this.

for i, player in pairs(game.Players:GetPlayers()) do
-- You can also use :GetChildren(), but I highly suggest that you use :GetPlayers()

Now it will work like a charm, you're welcome.

soved

0
Still not working pluginfactory 463 — 7y
Ad

Answer this question