Script not teleporting player

I have set up a script to teleport all players in the server when I press a button, but the script isn’t printing or teleporting.

LocalScript, under the part to teleport to:

game.ReplicatedStorage.Events.Obby.OnClientEvent:Connect(function()
	print("Attempting to teleport...")
	game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(script.Parent.Position)
	print("Player should be teleported.")
end)

Script, under the TextButton that triggers the teleport:

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.Events.Obby:FireAllClients()
end)
1 Like

You’re giving a Vector3 for a CFrame, maybe try for this line,

game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = script.Parent.CFrame

Also you never mentioned any errors, were there any?

I will try the line now. Also, there were no errors in the output.

No, the line didn’t work. :thinking:

Wait wait I see the issue. You’re calling a RemoteEvent for clients…On the client?

Okay for these scripts, just change the remote event to

game.ReplicatedStorage.Events.Obby.OnServerEvent:Connect(function(player)
	print("Attempting to teleport...")
	player.Character.HumanoidRootPart.CFrame = script.Parent.CFrame
	print("Player should be teleported.")
end)

And the button line to

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.Events.Obby:FireServer()
end)
1 Like

Just to clarify, the first script will work on a LocalScript, and the second will work on a server script, correct?

The 2nd script is the button so localscript, the 1st script must be a regular script, not a local script

Oh, okay. I will change the types and try the scripts now.

I got an error saying:
Cframe is not a valid member of Part "Workspace.ObbySpawn"

Capitalize the F in CFrame, I think I forgot to do that

It worked, thank you so much! I am going to mark your post with both scripts as the solution, you should probably fix the f

1 Like

I fixed up the F meaning I have paid my respects.

If you have anymore issues don’t be afraid to make another post!

1 Like

I was just testing the game with my main and my alt, but the game only teleported my main when I tried to teleport everyone. How would I fix this?

As of now, the teleport only works for you when press the button, it doesn’t teleport others. If you want it to teleport everyone when a single person presses the button, you can do this in the OnServerEvent

game.ReplicatedStorage.Events.Obby.OnServerEvent:Connect(function()
	for _,player in pairs(game.Players:GetPlayers()) do
		if not player.Character then continue end
		
		print("Attempting to teleport...")
		player.Character.HumanoidRootPart.CFrame = script.Parent.CFrame
		print("Player should be teleported.")
	end
end)
1 Like

The for loop seems to missing a do, but other than that it works!

1 Like

Thanks for pointing that out,I’ve fixed it!

I really need to proof read my code

1 Like