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

How to Click detect collect points?

Asked by 4 years ago
Edited 4 years ago

This is the standard leaderboard code.

game.Players.PlayerAdded:connect(function(plr)
    local f = Instance.new("Folder", plr)
    f.Name = "leaderstats"
    local coins = Instance.new("IntValue", f)
    coins.Name = "Coins"
    coins.Value = 0
end)

Click collect: What should I add to the code to work? the I click, I will earn + 1point/coins for example.

function onClicked()
        if model:FindFirstChild("Humanoid") ~= nil then
            if model.Humanoid:GetState() == Enum.HumanoidStateType.Dead then
                --]] put the code collect points
            end
        end
        button.Regen:Play()
    end

button.ClickDetector.MouseClick:Connect(onClicked)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

ClickDetector.MouseClick event has Player instance (the Player who click the detector). So the "click collect" script would be like this:

function onClicked(player) --this is the player instance from the event
    if model:FindFirstChild("Humanoid") ~= nil then
        if model.Humanoid:GetState() == Enum.HumanoidStateType.Dead then
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1 --this will make the player earn 1 coin
        end
    end
    button.Regen:Play()
end

button.ClickDetector.MouseClick:Connect(onClicked)
Ad

Answer this question