Teleporting script isn't working

I’m trying to make a teleport script where it teleports every player inside the game. And it’s not working, I’m getting no errors, I added print statements and they didn’t print. The script I used is a normal script that I put inside of ServerScriptService:

local target = game.Workspace.Target.CFrame
for i, player in ipairs(game.Players:GetChildren()) do
	print("Waiting")
	if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
		wait(5)
		print("Working")
		player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, i * 5, 0)
	end
end

Is this your whole script? If so, the script only runs when the game starts.

1 Like

I wrote it that way for testing purposes.

But is that your whole script?

Yes that is the whole entire script.

As I said in my first reply:

You need to add a wait at the top of the script so you can load in.

1 Like

Oh that’s why it wasn’t working. Thanks for your help.

Are you sure you wanna be multiplying it by 5 and not adding?

This probably due to the fact that players aren’t loading in before the script is fired. I would use an event like PlayerAdded where for when each player is added they get teleported.

@COUNTYL1MITS adding a wait at the top is not good practice, and you shouldn’t do that normally when waiting for something to load.

Like I said, this script that I wrote was for testing purposes.

This is not the final script as OP said here:

My point is it doesn’t matter whether it is for testing things or not, you still shouldn’t practice badly because it can affect how well you script in the future. Even if it is for when a round starts or something, you shouldn’t use wait() like that, you should call it off an event or use WaitForChild() when waiting for something to load in.

He probably will remove the wait() when it is in the final script.

I understand now. But in final scripts, I do remove the wait() and replace it with PlayerAdded.

1 Like