--Title can someone tell me whats wrong?

here's the codes

(Buy item in textbutton)

local plr = game.Players.LocalPlayer
local leaderboard = plr:WaitForChild("leaderstats")
script.Parent.MouseButton1Click:Connect(function()
	local JumpCoil = game.ReplicatedStorage.JumpCoil
	if leaderboard.Coins.Value >= 50 then
		local Rep = JumpCoil:Clone()
		Rep.Parent = plr.Backpack
		leaderboard.Coins.Value = leaderboard.Coins.Value -30		
	end
end)

leaderstats

game.Players.PlayerAdded:connect(function(player)
	local leaderstats = Instance.new("IntValue", player)
	leaderstats.Name = "leaderstats"

	local Coins = Instance.new("IntValue", leaderstats)
	Coins.Name = "Coins"
	Coins.Value = 0
end)

save leaderboard

local AUTO_SAVE = true			
local TIME_BETWEEN_SAVES = 60	
local PRINT_OUTPUT = true		
local SAFE_SAVE = true		
---------------------------------

local players = game:GetService("Players")
local dataStoreService = game:GetService("DataStoreService")
local leaderboardData = dataStoreService:GetDataStore("LeaderStats")

local function Print(message)
	if PRINT_OUTPUT then print(message) end
end

local function SaveData(player)
	if player.userId < 0 then return end
	player:WaitForChild("leaderstats")
	wait()
	local leaderstats = {}
	for i, stat in pairs(player.leaderstats:GetChildren()) do
		table.insert(leaderstats, {stat.Name, stat.Value})
	end
	leaderboardData:SetAsync(player.userId, leaderstats)
	Print("Saved "..player.Name.."'s data")
end

local function LoadData(player)
	if player.userId < 0 then return end
	player:WaitForChild("leaderstats")
	wait()
	local leaderboardStats = leaderboardData:GetAsync(player.userId)
	for i, stat in pairs(leaderboardStats) do
		local currentStat = player.leaderstats:FindFirstChild(stat[1])
		if not currentStat then return end
		currentStat.Value = stat[2]
	end
	Print("Loaded "..player.Name.."'s data")
end

players.PlayerAdded:connect(LoadData)
players.PlayerRemoving:connect(SaveData)

if SAFE_SAVE then
	game.OnClose = function()
		for i, player in pairs(players:GetChildren()) do
			SaveData(player)
		end
		wait(1)
	end
end

while AUTO_SAVE do
	wait(TIME_BETWEEN_SAVES)
	for i, player in pairs(players:GetChildren()) do
		SaveData(player)
	end
end

i'm so near my goal ;(