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

Respawn (not kill) on touch?

Asked by
ghaybe 5
6 years ago

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

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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))
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

Answer this question