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

Weapon Persistance. Any help?

Asked by 8 years ago

Im trying to get together a script that will save "ONLY" the weapons that go into StartGear. There are shops that when you buy the item it goes into StarterGear. However when I leave the server and come back it does not remember that I purchased it...

Here is thy script:

game.Players.PlayerRemoving:connect(function(p)
if p:findFirstChild("StarterGear") then
p:SaveInstance("SavedStatPNum"..tostring(game.PlaceId),p.StarterGear)
end
end)
game.Players.PlayerAdded:connect(function(p)
for k = 1, 60, 0.03 do
wait()
if p:findFirstChild("StarterGear") and p.DataReady then break end
end
local Loaded = nil
if p:findFirstChild("StarterGear") and pcall(function() Loaded =  p:LoadInstance("SavedStatPNum"..tostring(game.PlaceId)) end) then
for j, v in pairs(Loaded:GetChildren()) do
pcall(function() p.StarterGear[v.Name].Value = v.Value end)
end
end
end)

1 answer

Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

First of all, you need to tab your script properly:

game.Players.PlayerRemoving:connect(function(p)
    if p:findFirstChild("StarterGear") then
        p:SaveInstance("SavedStatPNum"..tostring(game.PlaceId), p.StarterGear)
    end
end)
game.Players.PlayerAdded:connect(function(p)
    for k = 1, 60, 0.03 do
        wait()
        if p:findFirstChild("StarterGear") and p.DataReady then
            break
        end
    end
    local Loaded = nil
    if p:findFirstChild("StarterGear") and pcall(function()
        Loaded =  p:LoadInstance("SavedStatPNum"..tostring(game.PlaceId))
    end) then
        for j, v in pairs(Loaded:GetChildren()) do
            pcall(function()
                p.StarterGear[v.Name].Value = v.Value
            end)
        end
    end
end)

In order to make scripts remember, you are going to have to use Data Stores.

You can only save strings with Data Stores, so you are going to need to use JSON Encode in order to save Lua tables. See how to do that here.

Happy reading!

0
Well I used this exact script but for my leader board, and it works for that... CarterTheHippo 120 — 8y
0
Your script uses Data Persistence, which is deprecated. Try to switch to Data Stores. Validark 1580 — 8y
Ad

Answer this question