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

Player touched a part and gets respawned?

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

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.

2 comments

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.

0

yes it was just an example, although i rarely have to wait for anything in workspace.

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