Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Teleport to game on death doesn't work?

So, I have been working on an elimination mode for a FPS game of mine. I made a script to teleport to a different game when you die. When I tried the game on the website, I did not teleport to the specified game. Here is the script I used:

game.Players.LocalPlayer.Character:WaitForChild('Humanoid').Died:Connect(function()
	wait(0.1)
	game.GetService('TeleportService'):Teleport(4833723678, game.Players.LocalPlayer)
end)

Will anyone help with this issue?

2 comments

0

Is this a localscript? Also was there anything in the output?

0

yes, it was a localscript. it was originally a part of a death screen script, so i kept it in startergui. do you know where i should put the script?

1 answer

✓ Accepted answer

I ran your program within my own place, it turned out the Character was loading too slow, a simple fix.

local TeleportService = game:GetService("TeleportService")
local GamePlaceId = 4833723678

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

Humanoid.Died:Connect(function()
	TeleportService:Teleport(GamePlaceId)
end)

It's also a better practice to leave containers to their respective purpose, so do not place any other code that doesn't manage a UI element within StarterGui. The best place to store a program like so would be StarterPlayerScripts.

8 comments

0

so when i tried your script, i put in all the stuff you put in your answer, tried it both as a LocalScript and Script, and they neither worked. could you maybe give some more instructions, or if i did the script wrong how to fix it?

0

I'm unsure as to what is occurring on your end, but my script works fine. I am teleported to a screen saying "Somewhat realistic FPS". Ensure you're testing this feature in-game as TeleportService cannot function in Studio. To make sure that your changes are uploaded, go to File > Publish To ROBLOX and then test it once more!

0

the issue may be caused by where i am putting the script? might you know where i should put it?

0

i put it in StarterPlayerScripts like as you first instructed, then i decided to put it in StarterCharacterScripts.

0

Ensure it is a LocalScript underneath StarterPlayer > StarterPlayerScripts. If this code is not entirely the code above, some other code may be interrupting it.

0

well, the script works now! i made a test place and put the script in StarterCharaterScripts then tested it.

0

Great, then would you mind accepting my answer?

0

okay, sure!

This discussion is preserved as it was. New answers, comments, and votes are closed.