New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
Log in to vote

My save data on PlayerRemoving script is not working?

Asked by 10 days ago
Edited 10 days 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)
local ItemsToSave = {}
        for i,v in pairs(plr.PlayerScripts.Items:GetChildren())do
            table.insert(ItemsToSave, v.Name)

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

there might be a better way but could you move the playerscripts before the players leaves than save then destroy tylergoatboy 48 — 10d
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 265 — 10d
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 265 — 10d

Answer this question