Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Teleport to game on death doesn't work?

Asked by 4 years ago

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?

0
Is this a localscript? Also was there anything in the output? greenhamster1 180 — 4y
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? Humanitoria 2 — 4y

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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.

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? Humanitoria 2 — 4y
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! Ziffixture 6913 — 4y
0
the issue may be caused by where i am putting the script? might you know where i should put it? Humanitoria 2 — 4y
0
i put it in StarterPlayerScripts like as you first instructed, then i decided to put it in StarterCharacterScripts. Humanitoria 2 — 4y
View all comments (4 more)
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. Ziffixture 6913 — 4y
0
well, the script works now! i made a test place and put the script in StarterCharaterScripts then tested it. Humanitoria 2 — 4y
0
Great, then would you mind accepting my answer? Ziffixture 6913 — 4y
0
okay, sure! Humanitoria 2 — 4y
Ad

Answer this question