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

DataStore + leaderstats Not working?

So, I'm trying to make a DataStore and a Leaderstats script all in one, the script is a normal script in ServerScriptService

game.Players.PlayerAdded:connect(function(player)
	local key = "user_"..player.UserId	
	local folder = Instance.new("Folder")
	folder.Parent = player
	folder.Name = "stores"
	local leaderstats = Instance.new("Folder")
	leaderstats.Parent = player
	leaderstats.Name = "leaderstats"	
	local money = Instance.new("IntValue", player)
	money.Name = "Money"
	local lemon = Instance.new("IntValue")
	lemon.Parent = player.stores
	local dss = game:GetService("DataStoreService")
	local moneyds = dss:GetDataStore("money")
		
	
		
	moneyds:UpdateAsync(key, function(oldValue)		
		if oldValue	== 0 then
			local newValue = 0
			newValue = newValue + 60
			return newValue
		end	
	end)
	money.Value = moneyds:GetAsync(key)	
end)

Sorry if this is completely wrong, it's been a while since I've done DataStores

1 comment

0

Btw, make sure Studio API Access is Enabled. ;)

1 answer

✓ Accepted answer

I will fix that datastore part for yah!

game.Players.PlayerAdded:connect(function(player)
	local key = "user_"..player.UserId  
	local folder = Instance.new("Folder")
	folder.Parent = player
	folder.Name = "stores"
	local leaderstats = Instance.new("Folder")
	leaderstats.Parent = player
	leaderstats.Name = "leaderstats"    
	local money = Instance.new("IntValue", player)
	money.Name = "Money"
	local lemon = Instance.new("IntValue")
	lemon.Parent = player.stores
	local dss = game:GetService("DataStoreService")
	local moneyds = dss:GetDataStore("money")

	local moneyval = moneyds:GetAsync(key) or 60
	money.Value = moneyval
end)

1 comment

0

I re-wrote the whole script and it works, but thanks for the help anyway!

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