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

Why is the DataStore not working?

So I made a DataStore script in and it did not work. Any fixes?

Faulty script 1:

local DataStore = game:GetService("DataStoreService"):GetDataStore("PeasStore")


game.Players.PlayerAdded:connect(function(player)
	
	local stats = Instance.new("IntValue", player)
	stats.Name = "leaderstats"
	
	local cash = Instance.new("IntValue", stats)
	cash.Name = "Money"
	cash.Value = cash.Value + 100
	
	local key = "player-"..player.userId
	
	local savedValues = DataStore:GetAsync(key)
	
	if savedValues then
		--Save format: {cash, coins}
		cash.Value = savedValues
	else
		local valuesToSave = {cash.Value}
		DataStore:SetAsync(key, valuesToSave)
	end
	
end)

Faulty code 2:

local DataStore = game:GetService("DataStoreService"):GetDataStore("PeasStore")

game.Players.PlayerRemoving:connect(function(player)
	
	local key = "player-"..player.userId
	
	--Save key: {cash}
	local valuesToSave = {player.leaderstats.Money.Value}
	DataStore:SetAsync(key, valuesToSave)
	
end)

1 answer

✓ Accepted answer

You must use Start Server instead of Play Solo, otherwise Studio will not be able to use DataStores. Also, you must Enable API Access in Studio.

1 comment

0

I did start a server, and also enabled the API access in studio, but it doesn't work.

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