Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

My save data on PlayerRemoving script is not working?

Asked by 4 months ago
Edited 4 months ago

Soo.. yeah. Datastores aren't exactly my thing, so here goes:

So I want a script to save multiple tables from different sources. All these sources are inside the Player Instance.

When I leave the game it saves the first table fine, but the second one returns with this error message: "PlayerScripts is not a valid member of Player".. Which is odd because.. well.. it is.

I looked into it and apparently the player leaves the game quicker than the script can run through the table and save everything, which is a problem.

local ToolsToSave = {}
        for i,v in pairs(plr.Backpack:GetChildren())do
            table.insert(ToolsToSave, v.Name)
        end
local ItemsToSave = {}
        for i,v in pairs(plr.PlayerScripts.Items:GetChildren())do
            table.insert(ItemsToSave, v.Name)
        end

This is the script ^

Correct me if I'm wrong but I think it takes too long to save before everything in the player is packed up. Any help is appreciated. Is there any way to delay the player leaving the game. Or maybe there's a more effective way to grab everything I need?

Thanks - FlabbyBoiii

0
there might be a better way but could you move the playerscripts before the players leaves than save then destroy tylergoatboy 82 — 4mo
0
Try to avoid parenting things to the player; Instead, create a session table immediately when the player joins the game. Then save with PlayerRemoved/BindToClose, then set the session table[player] = nil to avoid memory leaks. SteelMettle1 268 — 4mo
0
YouTube is a great learning asset, but almost all of the youtubers will use instances way too much as a way for them to save time. Try to use variables/tables in code rather than creating objects. SteelMettle1 268 — 4mo

Answer this question