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

Datastore Not Working? what did i do wrong?Gold not saving?

code here btw verry sloppy code cause im bad at scripting

local Datastore = game:GetService("DataStoreService")

local MyData = Datastore:GetDataStore("FQ34FFHH44L3")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local cash = Instance.new("IntValue")
	cash.Name = "Gold"
	cash.Parent = leaderstats
	
	local data
	local sucsess ,errormessage = pcall(function()
		data = MyData:GetAsync(player.UserId.."-cash")
		
	end)
	if sucsess then
		cash.Value = data
	else
		print("there was a error saving")
		warn(errormessage)
		
	end
end)
game.Players.PlayerRemoving:Connect(function(player)
	local sucsess, errormessage = pcall(function()
	 MyData:GetAsync(player.UserId.."-cash",player.leaderstats.gold.value)
	
	end)
	if sucsess then print("player data saved succsefully")
	else
		print("There was a error")
	warn(errormessage)
	end
end)

1 answer

✓ Accepted answer

Your problem is in line 29. Instead of getting the async again, you will want to set the async using ":SetAsync()" If it still doesn't work, please specify the error that it throws to make our jobs easier. I hope this helps! ~mc3334

5 comments

0

It still doesnt work but i think it would be easyer if u could acces the output add me on rblx and i will add u in a teamcreate

0

Here is an example I just typed up for you. Im pretty sure there are also some minor errors throughout the script: https://pastebin.com/2Z3X6USG

0

Its private

0

my bad

0

fixed^

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