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

Player touched a part and gets respawned?

Asked by
O_3I 0
5 years ago

Hi, I'm making an obby and I want to make it so if you fall you get respawned instantly when you touched the part that has the script

1 answer

Log in to vote
-1
Answered by 5 years ago

This isn't a request site, but I'm feeling nice right now. First, we'll make use of the Touched event in a server script. This assumes that you have a server script inside a part in the workspace:

local part = workspace.Part

part.Touched:Connect(function(hit)
    local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
    if plr then
        plr:LoadCharacter()
    end
end)

We use the :GetPlayerFromCharacter() method to find the character's player, and then load the character from there, which respawns the character.

1
Not sure the exact scenario this would be used in, but I would recommend you use WaitForChild to ensure the part has been loaded. lunatic5 409 — 5y
0
yes it was just an example, although i rarely have to wait for anything in workspace. Gey4Jesus69 2705 — 5y
Ad

Answer this question