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)
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!