Saving data on PlayerRemoving not working?

I’m trying to get my script to save something that is currently equipped upon the player leaving so that when they rejoin, they’ll spawn in with it still equipped. I got together a script for it, but it doesn’t seem to be working.

Code:

Players.PlayerRemoving:Connect(function(plr)
	if plr.Character.Rank.Rank.UIGradient:FindFirstChildWhichIsA("Script") then
		local lastnt = plr.Character.Rank.Rank.UIGradient:FindFirstChildWhichIsA("Script").Name
		ntStore:SetAsync(plr.UserId, lastnt)
	end
end)

Error:
image

Note that the thing I’m referencing does exist before the player leaves, but the script doesn’t seem to be registering it in the context of the script.

Which line that you have shown is line 131? My assumption as of now is that .Rank.Rank is a mistake

The line you are referencing is line 131, but as I mentioned earlier the thing I’m referencing does exist before the player leaves – the script just doesn’t seem to register that in the PlayerRemoving context.

By the time a player is removing, plr.Character does not exist. It’s already been deleted. This is the problem. Please do not store critical information like this on the character Model; store it on the Player.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.