Hey fellow developers, I have a question- how do I get the position of a player when he leaves the game, by the time PlayerRemoving fires the character is already deleted, how can I do this?
I haven’t really messed with the character when they leave, but a solution could be to store the player’s humanoid root part when the character respawns.
local hrps = {}
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local hrp = char:WaitForChild("HumanoidRootPart")
hrps[plr.UserId] = hrp
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
local hrp = hrps[plr.UserId]
if hrp then
hrps[plr.UserId] = nil
local position = hrp.Position
print(position) -- last position of the character before they left
end
end)
I’ll test that! thanks for replying.
It worked, thanks for your help!
1 Like