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

Teleporting after spawning (after dying)?

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)

2 comments

0

No the value does not reset after death

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.

2 answers

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

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 :)

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