You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
i want to detect when a player respawned
What is the issue? Include screenshots / videos if possible!
how do i do it
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.
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.
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)
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)
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)
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)
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.
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.