How to detect when a person got respawned

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

i want to detect when a player respawned

  1. What is the issue? Include screenshots / videos if possible!

how do i do it

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub? no

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

3 Likes

You would use Player.CharacterAdded to detect when a player respawns, also next time please look for solutions on the developer hub before making a post.

3 Likes

ok let me trY it iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii

it didnt worked sorry cant give you a solution

try this

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character) --every time he spawns
		print(player.Name.." has spawned in / respawned")
		character:WaitForChild("Humanoid").Died:Connect(function() --every time he dies and NOT respawns
			print(player.Name.." has died!")
		end)
	end)
end)

both of your replies does the same but what i want is to teleport a player when it got respawned

teleport into a new place or teleport into a certain part location?

yes
i want them to teleport to a part

game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char) -- Detects When The Player's Character Gets Added.
char.HumanoidRootPart.CFrame = YourPartCFrame -- Teleports The Player to your cframe that you assigned.
end)
end)

it dosent work here is my scripts

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char) -- Detects When The Player's Character Gets Added.
		char.HumanoidRootPart.CFrame = workspace.Spawn:WaitForChild(plr.leaderstats.Stages.Value).CFrame -- Teleports The Player to your cframe that you assigned.
	end)
end)

Output no errors
Workspace:
Screenshot 2022-08-08 161809

why not use teams. (had to put more letters so dont mind this closed message) btw what game are u making to make it specific

1 Like

ali’s difficulty chart obby

this is what im making

oh so ur making like checkpoints for the game?

You could simply use the function CharacterAdded you use it on the player. Here is an example.

local Tool = game.ReplicatedStorage.Tool
local Player = game.Players.LocalPlayer

Player.CharacterAdded:Connect(function()
    Tool.Parent = Player.Backpack
end)

(That is in a local script)

i need it on a server script and i alredy tried that with the other solutions


what?, why is it error type?

Hmm, you can try to make a leaderstats. Idk if this would work tbh but it doesn’t hurt to try.

     local checkpoints = workspace.Checkpoints

game.Players.PlayerAdded:Connect(function(player)
 	local leaderstats = Instance.new("Folder")
   	leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local stage = Instance.new("IntValue")
    stage.Name = "Stage"
    stage.Value = 1
    stage.Parent = leaderstats

    player.CharacterAdded:Connect(function(character)
	    local humanoid = character:WaitForChild("Humanoid")
	    wait()
	    character:MoveTo(checkpoints[stage.Value].Position)
	    humanoid.Touched:Connect(function(hit)
		    if hit.Parent == checkpoints then
			    if tonumber(hit.Name) == stage.Value + 1 then
				    stage.Value = stage.Value + 1
			    end
		    end
	    end)
    end)
end)

Put it in ServerScriptService. Btw you’ll need to make sure that the part where the player steps on is named by numbers. Sorry if it doesn’t work or it doesn’t make any sense (which i assume it is). I’m still learning scripting. I find it helpful for me to help people out.

3 Likes

Setting the CFrame of the HumanoidRootPart won’t necesssrily work. Instead, you should either use Model:MoveTo, Model:PivotTo, or Model:SetPrimaryPartCFrame. Here’s how I’d do it:

--This will work on the server.

local Players = game:GetService("Players")

local function onCharacterAdded(char)
     local pos = workspace.Spawn:WaitForChild(Players:GetPlayerFromCharacter(char).leaderstats.Stages.Value or 1).Position --Get the position (Vector3)
     char:MoveTo(pos) --Set the position with MoveTo(). This will put the player above the spawn point (or the closest clear location above the spawnpoint).
end

local function onPlayerAdded(player)
     player.CharacterAdded:Connect(onCharacterAdded) --Connecting character added event to function.
end

game.Players.PlayerAdded:Connect(onPlayerAdded) --Connecting player added event to function.

I hope this helps, please ask any questions if necessary. Also, I wrote this on my phone, as a result their may be typos, and I used spaces instead of tabs. You may want to check through for those kinds of errors when testing before saying this method doesn’t work.

1 Like