I have a weird problem, when the character leaves I want to drop the flag in the last position he was before he left. However when PlayerRemoving is fired the character object is already destroyed, how would I get the last position?
Yah I could constantly save the characters position in a table, but that seems inefficient.
Yah I already drop it when they die. When the player is leaving I don’t think he’s killed, the character is removed.
Or are you suggesting to drop the flag any time a character is removed from the game? That might be a good idea since that fires when either the player dies or the player is leaving from the game and his character his/she is removing.
local function CharacterRemoving()
local CFrameComponents = Root.CFrame:components() -- Root is humanoid root part
CFrameComponents = HttpService:JSONEncode({Root.CFrame:components()}) -- Ready to save!
end
Then just save it!
(to retrieve use JSONDecode()
Connect function to Player.CharacterRemoving, obviously!
You could also possibly try using CharacterRemoving, as it might fire before the Character is removed. You would of course have to check if the Player is nil afterwards to make sure that the user left the game, and didn’t just reset.
That’s why using CharacterRemoving as well should give more consistent results, as I mentioned. Take a look at @nicemike40’s code. I think that is the optimal type of method you should use.