Leaderstat dosen't save

  1. What do you want to achieve?
    I want to make a leaderstat that saves.

  2. What is the issue?
    It dosent save

This is the code i used

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 oofs = Instance.new("IntValue")
	oofs.Name = "OOFS"
	oofs.Parent = leaderstats

	local rebriths = Instance.new("IntValue")
	rebriths.Name = "Rebirths"
	rebriths.Parent = leaderstats

	local oofsData, rebrithsData
	local success, errormessage = pcall(function()
		oofsData = ds:GetAsync("oofs-"..plr.UserId)
		rebrithsData = ds:GetAsync("rebirths-"..plr.UserId)
	end)

	if success then
		oofs.Value = oofsData
		rebriths.Value = rebrithsData
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local success, errormessage = pcall(function()
		ds:SetAsync("oofs-"..plr.UserId, plr.leaderstats.OOFS.Value)
		ds:SetAsync("rebirths-"..plr.UserId, plr.leaderstats.Rebirths.Value)
	end)
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Was there any errors? (bruhhh)

This is weird. I have a very similar system and don’t have any error like this. Check your output. Also for your pcall, why did you not use {}

no i dident got any errors in the script

wdym by

why did you not use {}

sorry i am new to lua



I used a very similar script, possibly you can check this out, it was made a while back so it may not be perfect.

i’ve copied your code but the code dosen’t work because of somme errors.
I’ve maneged to fix somme of them but i cant fix them all because i dont know how

What sorts of errors have you recieved?

1 Like

Have you enabled Studio access to API services in Security settings? The script looks fine.

1 Like

Make sure API access and put some prints in the code, specifically after the pcall where you try to get the value of the data stores. Trying printing the error message, and the success message. Coders tip: Eliminate variables they may cause problems. Go down through your code and make sure each part works correctly.

Thanks i found the error i was writteing at one point rebirths wrong and that is why it wasent saving i think

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.