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

How do I get the Data Store to load the BoolValues?

Hello,

I'm having a hard time properly getting my Bool Values to save/load with the Data Store. I have Bool Values in the StarterGui that will turn the Value to true when purchased from the Shop:

hasGun = true hasSword = true etc.

Question: How do I get these to save and reload when the Data Store fires?

Here is my Data Store script that has been worked over several times now:

game.Players.ChildAdded:connect(function(newPlayer)
--Leaderstats Script, IntValues added for Cash, EXP, etc.


	stats.Parent = newPlayer
	
	local datastore = game:GetService("DataStoreService"):GetDataStore(newPlayer.Name.."Stats")
	
	local stats = stats:GetChildren()
    for i = 1, #stats do           
    	stats[i].Value = datastore:GetAsync(stats[i].Name)
		print("stat number "..i.." has been found")
	end
	
	local save_interval = 60 * 2 -- every 2 minutes
	
	wait(save_interval)
	
	while newPlayer.Parent do
		local stats = newPlayer.leaderstats:GetChildren()
	    for i = 1, #stats do           
	    	datastore:SetAsync(stats[i].Name, stats[i].Value)
			print("stat number "..i.." has been auto-saved")
		end
		
		wait(save_interval)
	end
end)

game.Players.ChildRemoved:connect(function(oldPlayer)
	local datastore = game:GetService("DataStoreService"):GetDataStore(oldPlayer.Name.."Stats")
	
	local stats = oldPlayer.leaderstats:GetChildren()
    for i = 1, #stats do           
    	datastore:SetAsync(stats[i].Name, stats[i].Value)
		print("stat number "..i.." has been saved")
	end

end)

I've looked at wikis, forums, youtube, I'm just having a really hard time with it, and would appreciate some help. =/ Thanks in advance.

1 answer

not sure but maybe you have to define stats before stats.Parent = newPlayer local stats = Instance.new("IntValue", stats) stats.Name = "leaderstats" stats.Parent = newPlayer

1 comment

0

Thanks for the response. :) I already have those defined in my Leaderstats script. All of my stats save/load just fine, its the bool Values for items that I can't get to save.

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