Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Weapon Persistance. Any help?

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

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!

2 comments

0

Well I used this exact script but for my leader board, and it works for that...

0

Your script uses Data Persistence, which is deprecated. Try to switch to Data Stores.

This discussion is preserved as it was. New answers, comments, and votes are closed.