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

How to respawn a player at location they died?

Hello, So I am making an airport game, and in the game, i have tickets as teams. Basically, how it works is that when you get changed into team and reset, it will give you a ticket according to your team.

What I want is, that when I change the players team, it will respawn them automatically on the position they were before. I change the teams using TeamColor in player, and I currently have no script done yet, because I have no clue how would I:

  1. Detect the change of teamColor
  2. Wait until the player spawns again
  3. Teleport the player to their previous location

and no, this is not script feeding, just tell me how would I make it, not give me the script.

1 answer

✓ Accepted answer

Well, now I am going answer your question step-by-step. Well, scripts are included as an example, because no one actually understands without an example.

  1. You can use GetPropertyChangedSignal, as Team is also the property of player, so you can use it like :
game.Players.PlayerAdded:Connect(function(plr)
	plr:GetPropertyChangedSignal("Team"):Connect(function()
		-- What you want to do
		-- If you want to kill the player, you can use BreakJoints
		plr:BreakJoints()
	end)
end)

Here, some more info on the topics discussed above.

https://developer.roblox.com/en-us/api-reference/function/Instance/GetPropertyChangedSignal

https://developer.roblox.com/en-us/api-reference/function/Model/BreakJoints

2 & 3. Well, it is easy if you want to teleport the player to the previous location. There's a sample example and comments as explanation.

game.Players.PlayerAdded:Connect(function(plr) -- Gets our player
	repeat wait() until plr.Character -- Doesn't execute the further code until the player's character is fully loaded
	plr.Character.Humanoid.Died:Connect(function() -- It will trigger when the player dies
		local RootPos = plr.Character.PrimaryPart.Position -- Gets the position of the HumanoidRootPart [Primary Part of player's character]
		plr.CharacterAdded:Connect(function(char) -- Triggers when the player respawns
			wait() -- waits for a bit, so that the fully character is loaded [Answer of 2]
			char:MoveTo(RootPos) -- Moves the character to the previous death position
		end)
	end)
end)

Here, some more info on the topics discussed above.

https://developer.roblox.com/en-us/api-reference/event/Humanoid/Died

https://developer.roblox.com/en-us/api-reference/function/Model/MoveTo

https://developer.roblox.com/en-us/api-reference/event/Player/CharacterAdded

Well, now you know how to do it, just connect them and get your script rolling without any issue.

Lemme know if it helps!

1 comment

0

Alr, I will check it out as soon as I get on the project & let you know if it worked / not. Thank you for replying!

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