Usually this works, it prints that it saved but still fails to save. I've been trying this for about 30 minutes and i'm still struggling to find an answer.

local dataService = game:GetService("DataStoreService"):GetDataStore("AWGIOJIOJHGHAWH")

game.Players.PlayerAdded:Connect(function(plr)
	local stats = Instance.new("Folder", plr)
	stats.Name = "leaderstats"
	
	local ReflectionTime = Instance.new("NumberValue", stats)
	ReflectionTime.Name = "ReflectionTime"
	
	local key = plr.UserId.. "-key"
	
	local savedValues = dataService:GetAsync(key)
	
	if savedValues then
		ReflectionTime.Value = savedValues[1]
	else
		local values = {ReflectionTime.Value}
		dataService:SetAsync(key, values)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	print("Player Leaving")
	local ReflectionTime = plr:WaitForChild("leaderstats"):WaitForChild("ReflectionTime")
	
	local key = plr.UserId.. "-key"
	local values = {ReflectionTime.Value}
	dataService:SetAsync(key, values)
	print("Saved")
end)

Thanks!

2 comments

0

Most of the cases, you can't use DataStore in Studio, it should use in real game.

0

Make sure you have filtering enabled, in my experiences it glitches with it off. :/