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

Currency DataSave not working?

Hello! I always had problems with DataSave, so I decided to follow an AlvinBlox's tutorial. It is still not working though. When I give myself some cash by the console, after leaving, they disappear. Why? Here's my code:


local DataStoreService = game:GetService("DataStoreService")

local myDataStore = DataStoreService:GetDataStore("myDataStore")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local cash = Instance.new("IntValue")
	cash.Name = "Korona"
	cash.Parent = leaderstats
	
	local data 
	local success, errormessage = pcall(function()
		data = myDataStore:GetAsync(player.UserId.."-cash")
	end)
	
	if success then
		cash.Value = data
	else
		warn("There was an error whilst getting your data.")
	end
end)

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

1 comment

0

Tee Hee

1 answer

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