Broken Datastore

Every time I leave the game I get an error for too many requests, which crashes my studio.
It also does not save! Any help?

local stat = "Candy Canes"
local startamount = 50


local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("LeaderStatSave")


game.Players.PlayerAdded:connect(function(player)
	local leader = Instance.new("Folder",player)
	leader.Name = "leaderstats"
	local Cash = Instance.new("IntValue",leader)
	Cash.Name = stat
	local PlayerData = ds:GetAsync(player.UserId)
	Cash.Value = PlayerData
	while true do
		wait(10)
		ds:SetAsync(player.UserId, {
			Canes = Cash.Value,
		})
	end
end)

game.Players.PlayerRemoving:connect(function(player)
	ds:SetAsync(player.UserId, {
		Canes = player.leaderstats["Candy Canes"].Value
	})
end)

fixed it ! fdsfdsfdsfdsdfgfdhghfghgf

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