Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you find the player who clicked a brick?

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.