local DSS = game:GetService('DataStoreService')
local mainDS = DSS:GetDataStore('CoinsData')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Events = ReplicatedStorage:FindFirstChild('Events')
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new('Folder', player)
leaderstats.Name = "leaderstats"
local coins = Instance.new("IntValue", leaderstats)
coins.Name = "Coins"
local data = mainDS:GetAsync(player.UserId)
if data then
if data[1] then
coins.Value = data[1]
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local coins = leaderstats:WaitForChild("Coins")
mainDS:SetAsync(player.UserId, {coins.Value})
end)
Button = script.Parent
player = game.Players.LocalPlayer
Button.MouseButton1Click:Connect(function()
local leaderstats = player:WaitForChild("leaderstats")
local coins = leaderstats:WaitForChild("Coins")
coins.Value += 1
end)