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

My data store saving does not work, what do I do?

So I was using alvinblox's tutorial on how to make a simulator part 3, and I did the data store but when I join the game on roblox and get the numbers to what I want and then rejoin, it didn't save. Heres the code:

local serverStorage = game:GetService("ServerStorage")
local DataStore = game:GetService("DataStoreService"):GetDataStore("PlayerSave3")

game.Players.PlayerAdded:Connect(function(player)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local intelligence = Instance.new("NumberValue")
	intelligence.Name = "Intelligence"
	intelligence.Parent = leaderstats
	
	local rebirths = Instance.new("IntValue")
	rebirths.Name = "Rebirths"
	rebirths.Parent = leaderstats
	
	local dataFolder = Instance.new("Folder")
	dataFolder.Name = player.Name
	dataFolder.Parent = serverStorage.RemoteData
	
	local debounce = Instance.new("BoolValue")
	debounce.Name = "Debounce"
	debounce.Parent = dataFolder
	
	local intelligenceData, rebirthsData
	
	local success,errormessage = pcall(function()
		intelligenceData = DataStore:GetAsync("intelligence-"..player.UserId)
		rebirthsData = DataStore:GetAsync("rebirths-"..player.UserId)
	end)
	
	if success then
		if intelligenceData then
			intelligence.Value = intelligenceData
			rebirths.Value = rebirthsData
		end
	end
	
end)

game.Players.PlayerRemoving:Connect(function(player)
	local success, errormessage = pcall(function()
		DataStore:SetSync("intelligence-"..player.UserId,player.leaderstats.Intelligence.Value)
		DataStore:SetSync("rebirths-"..player.UserId,player.leaderstats.Rebirths.Value)
	end)
end)
	

What is wrong here? [I did not add the size as I don't want that.]

3 comments

0

hmmm that should save...

0

you need to add a value to the numbers or it wont save

0

what numbers?

1 answer

✓ Accepted answer

You should put any errors you have next time, but I think I see the problem anyways.

game.Players.PlayerRemoving:Connect(function(player)
	local success, errormessage = pcall(function()
	        DataStore:SetSync("intelligence-"..player.UserId,player.leaderstats.Intelligence.Value)
	      	DataStore:SetSync("rebirths-"..player.UserId,player.leaderstats.Rebirths.Value)
	end)
end)

DataStore:SetSync() does not exist as a real function. What you're looking for is DataStore:SetAsync()

game.Players.PlayerRemoving:Connect(function(player)
	local success, errormessage = pcall(function()
	        DataStore:SetAsync("intelligence-"..player.UserId,player.leaderstats.Intelligence.Value)
	      	DataStore:SetAsync("rebirths-"..player.UserId,player.leaderstats.Rebirths.Value)
	end)
end)

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