I want to make it so that when the localplayer dies they are teleported to another game, so I made a localscript and inserted it into ReplicatedFirst and wrote this:
local TeleportService = game:GetService("TeleportService") local gameID = 2094965912 local player = game.Players.LocalPlayer player:WaitForChild("Humanoid").Died:connect(function() TeleportService:Teleport(gameID, player) end)
However, nothing happened. Can anyone please tell me what I'm doing wrong?
Hi there! "Humanoid" is located in the players character, so here's what the "player" variable should be:
local player = game.Players.LocalPlayer.Character
If this doesn't work, it may be because the server takes a while to load the character. Here's an alternative script, should the first one not work:
game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) character:WaitForChild("Humanoid").Died:connect(function() TeleportService:Teleport(gameID, player) end) end) end)
There ya are! :D
REVISED:
local script:
local player = game.Players.LocalPlayer.Character player:WaitForChild("Humanoid").Died:connect(function() game.ReplicatedStorage.RemoteEvent:FireServer(gameID) end)
Server script
game.ReplicatedStorage.RemoteEvent.OnServerInvoke:Connect(function(player,gameID) TeleportService:Teleport(gameID, player) end)
Remember that the player argument is given in remote events and functions!