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

looping script not running :moveto() for player?

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

2 comments

0

Local script? FE Is enabled so you might have to do it by the server.

0

not a localscript

1 answer

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

1 comment

0

Still not working

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