This script shows no error in the output, but when ever the block is removed, the leaderboard doesn't increase by anything. What is causing this issue?
local playerLeaderstats = {} --Table (anti exploit) game.Players.PlayerAdded:connect(function(player) playerLeaderstats[player] = {} playerLeaderstats[player]["Mined Blocks"] = 0 local leaderstats = Instance.new("Model") leaderstats.Name = "leaderstats" leaderstats.Parent = player local Mined = Instance.new("IntValue") Mined.Name = "Mined Blocks" Mined.Value = playerLeaderstats[player]["Mined Blocks"] Mined.Parent = leaderstats end) --From lines 15 to 24, I am trying to cause the block local block = game.Workspace.Part local click = block.ClickDetector local function onClick(playerWhoClicked) --When block is mined, remove the block (Lines 17 to 21) wait(5) block:Destroy() print("Block Mined") end for _, player in ipairs(game.Players:GetPlayers()) do if player:FindFirstChild("leaderstats") then player.leaderstats.Mined.Value = player.leaderstats.Mined.Value + 1 --Increase score by 1 once block has been mined end end block.ClickDetector.MouseClick:connect(onClick)
Instead of doing a loop, why don't you just do this inside the onClick function?
local function onClick(playerWhoClicked) --When block is mined, remove the block (Lines 17 to 21) wait(5) block:Destroy() print("Block mined") local stats = playerWhoClicked:FindFirstChild("leaderstats") if stats then stats["Mined Blocks"].Value = stats["Mined Blocks"].Value + 1 end end
~TDP