Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why isn't this leaderboard working?

Asked by 8 years ago

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)

1 answer

Log in to vote
0
Answered by 8 years ago

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

0
Thanks for the help! User#210 0 — 8y
Ad

Answer this question