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

Respawn (not kill) on touch?

I was trying to respawn a player when they touch a block. I've been using the following:

script.Parent.Touched:connect(function(Hit) Player = Game.Players:GetPlayerFromCharacter(Hit.Parent) if Player then Player:LoadCharacter() end end)

While this works, it causes the respawned player to lose their clothes. What would be the correct way to do it?

Thanks!

2 answers

Teleportation via either CFrames or Vector3 (CFrames are great for rotation and position but require more work, Vector3 just handles position.)

(unless, of course, there's another way to do it; i don't think so tho.)

Example:

game.Workspace.Player.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0, 50, 0))

This is due to using deprecated code.

global Game is deprecated, switch to game.

RBXScriptSignal:connect() is deprecated, switch to RBXScriptSignal:Connect().

Also, please put your code in a code block by highlighting it, and clicking the 'Lua' circle, or by clicking the 'Lua' circle and then pasting your code in between the tildes.

Player:LoadCharacter() has the same effect as resetting.

script.Parent.Touched:Connect(function(part)
    local plr = game:GetService('Players'):FindFirstChild(part.Parent.Name)
    if plr then
        plr:LoadCharacter()
    end
end)

Also, use DataModel:GetService( Instance className ) to get services, as indexing them with game.Service can error if the service is not found.

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