basically i've made sort of a "clicker" game where you click buttons to make bricks, and i've added a leaderboard and i want to make sure that the bricks actually count into the leaderboard statistics
this is the code that i'm using:
local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("BrickCountSaveSystem")
local ds2 = datastore:GetDataStore("DeathSaveSystem")
game.Players.PlayerAdded:connect(function(plr)
local folder = Instance.new("Folder", plr)
folder.Name = "leaderstats"
local BrickCount = Instance.new("IntValue", folder)
BrickCount.Name = "Bricks"
local deathcount = Instance.new("IntValue", folder)
deathcount.Name = "Deaths"
BrickCount.Value = ds1:GetAsync(plr.UserId) or 0
ds1:SetAsync(plr.UserId, BrickCount.Value)
BrickCount.Changed:connect(function()
ds1:SetASync(plr.UserId, BrickCount.Value)
deathcount.Value = ds1:GetAsync(plr.UserId) or 0
ds1:SetAsync(plr.UserId, deathcount.Value)
deathcount.Changed:connect(function()
ds1:SetASync(plr.UserId, deathcount.Value)
end)
end)
end)
game:GetService("Players").PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
character:WaitForChild("Humanoid").Died:connect(function()
player.leaderstats.Deaths.Value = player.leaderstats.Deaths.Value + 1
end)
end)
end)
heres the script inside the buttons that make the bricks if you guys need this aswell:
local aaa = script.Parent.Parent.BrickCounter
Clicks = aaa.Clicks
script.Parent.Parent.BrickCounter.SurfaceGui.TextLabel.Text = Clicks.Value
function onClicked()
Clicks.Value = Clicks.Value + 1
aaa.SurfaceGui.TextLabel.Text = Clicks.Value
end
script.Parent.ClickDetector.MouseClick:Connect(onClicked)
thanks in advance

1 comment
doesn't seem to work, there's no errors either