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 comment
Thanks for the help!