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

Why is my datastore not getting the data?

I'm sorry, I'm new to DataStores.

local DataStoreService = game:GetService("DataStoreService")

local myDataStore = DataStoreService:GetDataStore("DATA")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local tokens = Instance.new("IntValue", leaderstats)
	tokens.Name = "Tokens"
	tokens.Value = 0
	
	local data
	
	local success, errormessage pcall(function()
		data = myDataStore:GetAsync(player.UserId.."-Tokens")
	end)
	
	if success ~= nil then
		tokens.Value = data
	else
		print("There was an error while getting your data.")
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	
	local success, errormessage = pcall(function()
		myDataStore:SetAsync(player.UserId.."-Tokens",player.leaderstats.Tokens.Value)
	end)
	
	if success then
		print("Data succesfully saved.")
	else
		print("There was an error when saving data.")
		warn(errormessage)
	end
	
end)

1 comment

0

I've already enabled API services.

1 answer

✓ Accepted answer

I only looked at it for a second but I saw on line 15 you forgot an "=".

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