Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Saving Tools Script not working with Filtering Enabled?

Asked by 6 years ago

I made a script a while ago that saves the players tools when they leave the game and loads them back when the player enters the game. After I added filtering enabled to my game the script no longer works and for some reason it is breaking my leaderstats save script too. When I buy a weapon from the store, my coins goes down depending on how much I spent on the item. After rejoining the weapon is not saved and my coins are back to the way they were before i bought the item.

01local Inventory = {}
02 
03local function Spawned(Char)
04    local Plr = game.Players:GetPlayerFromCharacter(Char)
05    for i,v in pairs(Inventory[Plr]) do
06        if Plr['Backpack']:findFirstChild(v.Name) then
07            Plr['Backpack'][v.Name]:Destroy()
08        end
09        v.Parent = Plr['Backpack'] 
10    end
11    Inventory[Plr] = {}
12    Char:WaitForChild('Humanoid').Died:connect(function()
13        for i,v in pairs({Plr['Backpack'], Char}) do
14            for ii,vv in pairs(v:GetChildren()) do
15                if vv:IsA('Tool') then
View all 29 lines...

Also the leaderstats save on their own. So if I earn 20 coins in game they save, but not when I purchase an item.

0
Also yes it is in a Local Script. tawk1215 47 — 6y
0
PlayerAdded is server side only, connect, :wait, :findFirstChild are deprecated, use Connect, Wait, FindFirstChild User#19524 175 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

The main problem with your script is that it's local, and that you are trying to use the PlayerAdded event on a local script.

Also, don't use deprecated functions. (for example ":connect" should be changed to ":Connect".)

Also, here is the fixed script:

01local Inventory = {}
02 
03local function Spawned(Char)
04    local player= game.Players:GetPlayerFromCharacter(Char)
05    for i,v in pairs(Inventory[player]) do
06        if player['Backpack']:FindFirstChild-(v.Name) then
07            player['Backpack'][v.Name]:Destroy()
08        end
09        v.Parent = player['Backpack'] 
10    end
11    Inventory[player] = {}
12    Char:WaitForChild('Humanoid').Died:Connect(function()
13        for i,v in pairs({player['Backpack'], Char}) do
14            for ii,vv in pairs(v:GetChildren()) do
15                if vv:IsA('Tool') then
View all 29 lines...

! IMPORTANT ! This script must be a server-side script, and NOT a local-script.

Hope this helps.

Ad

Answer this question