for context: i'm new to Lua and i'm doing this weird thing where i have a normal leaderboard and that leaderboard shows how many bricks you and other people have made (i also made a global leaderboard of everyones scores but imma mess with that later)
the script that i'm using for the leaderboard is:
local datastore = game:GetService("DataStoreService") local ds1 = datastore:GetDataStore("BrickCountSaveSystem") game.Players.PlayerAdded:connect(function(plr) local folder = Instance.new("Folder", plr) folder.Name = "leaderstats" local BrickCount = Instance.new("IntValue", folder) BrickCount.Name = "Bricks" BrickCount.Value = ds1:GetAsync(plr.UserId) or 0 ds1:SetAsync(plr.UserId, BrickCount.Value) BrickCount.Changed:connect(function() ds1:SetAsync(plr.UserId, BrickCount.Value) end) end)
the script that makes the both "react' is:
local part = game.Players.leaderstats BrickCount = 0 game.Players.player.leaderstats.Bricks = BrickCount function onClicked() BrickCount = BrickCount+1 game.Players.player.leaderstats.Bricks = BrickCount end script.Parent.ClickDetector.MouseClick:Connect(onClicked)
i know that i've messed up the Players.leaderstats part, but idk how to dig out the leaderboard stats any other way, my brain too small but i'm betting i'll have to GetService my way into the leaderstats folder
what i'm trying to get is the brick value to increase by 1 with every click, so 1 button press = +1 Bricks, and so on
local part = script.parent --replace "part" with the name you gave the part local ClickDetector = Instance.new("ClickDetector") ClickDetector.Parent = part --again replace "part" with the name you used above ClickDetector.MaxActivationDistance = 15 --change the max to whatever you want it to be local db = true ClickDetector.MouseClick:Connect(function(click) if click.Parent:FindFirstChild("Humanoid") ~= nil then if db == true then db = false local player = game.Players:GetPlayerFromCharacter(click.Parent) player.leaderstats.BrickCount.Value = player.leaderstats.BrickCount.Value + 1 -- or whatever number you wanna reward for it wait(1) script.Parent:Remove() -- if you wanna have it removed, single use end end end)
something like this...
You usually do it like this in a server script:
player.leaderstats.YourValue.Value = "YourValue"
However, if they touched something and you want to change it like that, do:
local player = part.Parent:GetPlayerFromCharacter() player.leaderstats.YourValue.Value = "YourValue"
Hope this helped.