local stat = "Points"
local startamount = 0
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("LeaderStatSave")
local clickDetector = workspace.PartWithClickDetector.ClickDetector -- Adjust this line to reference your part
-- Handle when a player joins the game
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder", player)
leader.Name = "leaderstats"
local Cash = Instance.new("IntValue", leader)
Cash.Name = stat
Cash.Value = ds:GetAsync(player.UserId) or startamount
ds:SetAsync(player.UserId, Cash.Value)
Cash.Changed:connect(function()
ds:SetAsync(player.UserId, Cash.Value)
end)
end)
-- Handle when a player leaves the game
game.Players.PlayerRemoving:connect(function(player)
ds:SetAsync(player.UserId, player.leaderstats[stat].Value)
end)
-- Handle when the part is clicked
clickDetector.MouseClick:connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local points = leaderstats:FindFirstChild(stat)
if points then
points.Value = points.Value + 1
end
end
end)