Teleporting on the client teleports the whole server

So I was testing the teleport script I had in my game with my friend. It is activated once a .Touched event is pressed. But, when I read the documentation, it should only teleport the local player. Instead, it teleports the whole server to one place.

The script is laying in StarterGui, and it is activated once a part has been touched by a player in the workspace. The script is a LocalScript.

Here is event code I’m currently using:

teleport1.Touched:Connect(function()
	TeleportScreen2.Parent = PlayerGui
	TeleportService:Teleport(gameId1)
end)

I can’t seem to find any errors whatsoever. If you can help me out, I will really appreciate it!

The reason it happens if because you need to verify if the person who touched the part, this is because everyone has that localscript for the touched event, so if a single person touches the part, everyone will be affected as there’s no verification. You need to verify the person who touched, something like this should work

local player = game:GetService("Players").LocalPlayer

teleport1.Touched:Connect(function(hit)
	if player.Character and hit:IsDescendantOf(player.Character) then
		TeleportScreen2.Parent = PlayerGui
		TeleportService:Teleport(gameId1)
	end
end)

It checks if the localplayer’s character exists and if they do exist, check if the hit part is a descendant of their character, and if it is, teleport

Here’s a good read on that

3 Likes

Thanks! I will be sure to check out that post.

1 Like

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

1 Like