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?
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
.