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

How do I make a gun saving script for the players that have bought guns?

So I need help with making a script that will use 'datastore' to save guns that people have bought from the gun gui shop but I cant figure it out. I have similar code that uses 'datastore' to save stats like money. ~~~~~~~~~~~~~~~~~

--[[local DSService = game:GetService('DataStoreService'):GetDataStore('Protectiveroboz')
game.Players.PlayerAdded:connect(function(plr)
	--Define varibles
	local uniquekey='id'..plr.userId
	local leaderstats = Instance.new('IntValue',plr)
	local savevalue = Instance.new('IntValue')
	leaderstats.Name = 'leaderstats'
	savevalue.Parent = leaderstats
	savevalue.Name = 'Points'
	
	-- GetAsync
	local GetSaved = DSService:GetAsync(uniquekey)
	if GetSaved then
		savevalue.Value = GetSaved[1]
	else
		local NumbersForSaving = {savevalue.Value}
		DSService:SetAsync(uniquekey,NumbersForSaving)
	end
end)

game.Players.PlayerRemoving:connect(function(plr)
	local uniquekey = 'id-'..plr.userId
	local Savetable = {plr.leaderstats.Points.Value}
	DSService:SetAsync(uniquekey, Savetable)
	
	
end)]]~~~~~~~~~~~~~~~~~

Thats the code but does anyone know how to change it to save weapons?

1 comment

0

Well, you have to create a table that saves the names of the tools, then when they rejoin, find the tool's name in wherever it is and give it to them

1 answer

✓ Accepted answer

Sure. Script a for loop which finds all the weapons that the player has bought. It might look like this:

local tableForSavingWeapons = {}

for i,v in pairs() do -- use the GetChildren() for wherever you keep the weapons the player has purchased 
	tableForSavingWeapons[1] = v.Name
end

then save that table into your datastore. When a player joins the game just loop through all the items a player can buy with a for loop and give them all the items that match with the ones in the table you got from the datastore.

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