My leaderstat is not saving

Hi,

It’s not saving. What am I doing wrong?

local dataStoreService = game:GetService("DataStoreService")
local ds = dataStoreService:GetDataStore("DataStoreTest")

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr

	local touches = Instance.new("IntValue")
	touches.Name = "Touches"
	touches.Parent = leaderstats

	local touchesData, rebrithsData
	local success, errormessage = pcall(function()
		touchesData = ds:GetAsync("touches-"..plr.UserId)
	end)

	if success then
		touches.Value = touchesData
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local success, errormessage = pcall(function()
		ds:SetAsync("touches-"..plr.UserId, plr.leaderstats.touches.Value)
	end)
end)
1 Like

Have you enabled this?
Screenshot_6

Yes, it seems like there was something wrong with my game. I opened a brand new file enabled api again and it works now: )

2 Likes