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:
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.
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.