Teleport script teleports everyone

So I started using proximity prompt and made it teleport a person. However, it teleports everyone to the same place. I tried using a local script but it didn’t work. I am kinda new to scripting so please don’t judge my lack of knowledge.

Script:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local ProximityPrompt = script.Parent
		ProximityPrompt.Triggered:Connect(function(player)
			char:MoveTo(workspace.TeleportBlock.Position)
		end)
	end)
end)
1 Like

Change

char:MoveTo(workspace.TeleportBlock.Position)

to

player.Character:MoveTo(workspace.TeleportBlock.Position)

As well as apply @IEnforce_Lawz ’s changes mentioned below.

1 Like

Remove the PlayerAdded and Character added events. There is no reason for having them as the player value is passed through the parameters.

ProximityPrompt.Triggered:Connect(function(Player)
	local char = Player.Character
        char:MoveTo(workspace.TeleportBlock.Position)
end)
1 Like

Heya! It’s completely fine, I’ll give the explanation as to why your script is TP’ing all players:

  • Using CharacterAdded events and moving them with the char parameter will move all the Characters that are currently in the workspace

Well, how would you fix it? :thinking:

Just remove the PlayerAdded & CharacterAdded Events, those should only be necessary if you want to change things when a player or character joins

  • The script should still work fine, & using your ProximityPrompt’s Triggered parameter (As the player object who triggered it) would teleport that specific Character only

Fixed script:

local ProximityPrompt = script.Parent
ProximityPrompt.Triggered:Connect(function(player)
	player.Character:MoveTo(workspace.TeleportBlock.Position)
end)
2 Likes

Thank you! That solved the problem.

2 Likes