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

Help with getting player from ServerScript?

local gameFunction = coroutine.create(function(player)
	gameEvent:FireClient(player)
end)
		
for _, player in pairs(game.Players:GetPlayers()) do
	if player then
		coroutine.resume(gameFunction, player)
		gameInPlay = false
		wait(5)
		player.TeamColor = BrickColor.new("White")
		local playerFolder = player:WaitForChild("PlayerFolder")
		if playerFolder then
			local team = playerFolder:WaitForChild("Team")
			if team then
				team.Value = "White"
			end
		end
	end
end

What I have this script do is get the players in the server, and then fire an event. The reason I have a wait(5) is because the event that is fired leads to something in the local script which has a v in it also, so the wait(5) MUST stay. The problem I am having is it is not firing at the same time for each player.

I believe the problem is that it is going through each player, so it fires the event for Player1, waits 5, then fires for Player2. Is there a way to fire for every player in the server so the event is fired at the exact same time, and they all go back to TeamColor White at the exact same time?

2 comments

0

It isn't firing at the same time because of the wait. Use a coroutine if you can. http://wiki.roblox.com/index.php?title=Beginners_Guide_to_Coroutines

0

Editted with what I have. It now only fires for one player

1 answer

✓ Accepted answer

You need to have the code itself in a coroutine, not the fireclient.

for _, player in pairs(game.Players:GetPlayers()) do
	coroutine.resume(coroutine.create(function()
    		if player then
			gameEvent:FireClient(player)
			gameInPlay = false
			wait(5)
			player.TeamColor = BrickColor.new("White")
			local playerFolder = player:WaitForChild("PlayerFolder")
			if playerFolder then
				local team = playerFolder:WaitForChild("Team")
				if team then
					team.Value = "White"
				end
        		end
    		end
	end))
end

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