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

Why in-game is it teleporting one player only?

I'm creating a minigame-based game, and the main function is teleporting the players to the selected maps (from a server script in ServerScriptService). However, when testing it in multiplayer, I found out that it teleports one player and then teleports the next player when the round is over. Any help would be appreciated :).

for i,player in ipairs(game.Players:GetChildren()) do
		if player~=nil then
			if player.Character:FindFirstChild("HumanoidRootPart")~=false then
				print("its all relative!!!")
					if player.Character.Humanoid.Health~=0 then
						local ransp = mapSpawn[math.random(1,#mapSpawn)].CFrame*CFrame.Angles(0,180,0) + Vector3.new(0,3,0)
						print("ITS ALL RELATIVE")
						player.Character.HumanoidRootPart.CFrame=ransp
						wait()

						
					
			end
		end
	end

1 answer

✓ Accepted answer

Improvements

Use :GetService() for the Players service

Use :GetPlayers() instead of :GetChildren() to retrieve players in the game

You can place multiple conditions in a if statement with and / or

Use :SetPrimaryPartCFrame() to move the player's Character model instead of setting the CFrame of a part of their body (as it may move only the part and not the whole model)

Issues

ipairs iterates through a table until it hits a nil value and then stops, use pairs instead.

Revised Server Script

for i, player in pairs(game:GetService("Players"):GetPlayers()) do
	local root = player.Character:FindFirstChild("HumanoidRootPart")
	local human = player.Character:WaitForChild("Humanoid")
	if root and human.Health > 0 then
		local ransp = mapSpawn[math.random(1, #mapSpawn)].CFrame * CFrame.Angles(0, 180, 0) + Vector3.new(0, 3, 0)
		player.Character:SetPrimaryPartCFrame(ransp)
		wait()
	end
end

1 comment

1

THANK YOU SO MUCH <3 I THOUGHT MY GAME WAS OVER THANK YOU THANK YOU <3<3 :))

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