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

Teleporting after spawning (after dying)?

Asked by
RoyMer 301 Moderation Voter
9 years ago

Why is this not working? it is placed in StarterGui.

local player = game.Players.LocalPlayer
local spawn = player:WaitForChild("ds"):WaitForChild("Spawn")
local brick = game.Workspace.Spawns

Player = game:GetService("Players").LocalPlayer
Player.CharacterAdded:connect(function(character)

    if spawn.Value == 0 then
    player.Character.Torso.CFrame = CFrame.new(3, 0.2, 1)   
    end

    if spawn.Value == 1 then
    player.Character.Torso.CFrame = CFrame.new(53, 0.2, 1)  
    end
end)
0
No the value does not reset after death RoyMer 301 — 9y
0
I remember trying to 'teleport' my player by changing my Torso's CFrame, but it ended up not working. To fix it, I just change the HumanoidRootPart's CFrame instead of the Torso. Mr_Octree 101 — 9y

2 answers

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

The script in the player's PlayerGui will be loaded every time the player respawns, which means CharacterAdded will not fire because the character already exists.

Instead, just define character as character=Player.Character

Ad
Log in to vote
0
Answered by
MunimR 125
9 years ago

To elaborate on what 1waffle1 said basically what happens is that CharacterAdded never fires because by the time the LocalScript has loaded the Character will have already spawned. So a way around this issue is to do this.

local player = game:GetService("Players").LocalPlayer
local spawn = player:WaitForChild("ds"):WaitForChild("Spawn")
local brick = workspace.Spawns

repeat wait() until player.Character
local torso = player.Character:WaitForChild("Torso")
if spawn.Value == 0 then
    torso.CFrame = CFrame.new(3, 0.2, 1)   
end
if spawn.Value == 1 then
    torso.CFrame = CFrame.new(53, 0.2, 1)  
end

Hopefully this helps :)

Answer this question