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

How do you find the player who clicked a brick?

Asked by 10 years ago

I'm making a brick so when you click it, then it gives you a leaderstat cash. I just cant get it working to who clicked the brick.

I have a code that'll get the player if you TOUCH it, like collide.

local ting = 0 --debouncer

function onTouched(hit)

    if ting == 0 then --debounce check
    ting = 1 --activate debounce
    check = hit.Parent:FindFirstChild("Humanoid")

    if check ~= nil then 

        local user = game.Players:GetPlayerFromCharacter(hit.Parent)        local stats = user:findFirstChild("leaderstats") 

        if stats ~= nil then --If moneyholder exists then
            local cash = stats:findFirstChild("PartsClicked")
            cash.Value  = cash.Value +1
        end

    end

    ting = 0 --remove debounce
    end

end

script.Parent.Touched:connect(onTouched)

So can maybe someone help me convert this into the same thing but when you click it? I have the clickdetector and everything in it. Thank you.

1 answer

Log in to vote
0
Answered by
Lacryma 548 Moderation Voter
10 years ago
local ting = false --debouncer

function onClicked(player)

    if not ting then --debounce check
    ting = true--activate debounce

    local stats = player:findFirstChild("leaderstats") 

    if stats then --If moneyholder exists then
        local cash = stats:findFirstChild("PartsClicked")
        cash.Value  = cash.Value + 1
    end

    ting = false --remove debounce
    end

end

script.Parent.MouseClick:connect(onClicked)

MouseClick

Ad

Answer this question