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

How can I make this ClickDetector Script Local Only?

Okay so, I have this section in an obby where the player has to click on a part to "build" them. The problem is, this script works globally so it's happening for all players, so how could I have it only pop up for the player who clicked on it? Inside that brick there is a ClickDetector and inside the ClickDetector resides this script.
My Script (Class is Script, not LocalScript):

function BuildBrick()
	script.Parent.Parent.CanCollide = true
	script.Parent.Parent.Transparency = 0
	
end


script.Parent.MouseClick:Connect(BuildBrick)

2 comments

0

don't forget to accept my answer if it solves your problem.

0

It should be under the answer.

1 answer

✓ Accepted answer

It is possible to use a local script to listen to the mouse click event, as long as the local script is in a place they can run in, generally PlayerScripts. The only thing you'll need to change is script.Parent to the path of your click detector.

local clickDetector = ... -- # change to your clickdetector path

local function BuildBrick(client) -- # localise variable
    if client == game:GetService("Players").LocalPlayer then
        clickDetector.Parent.CanCollide, clickDetector.Parent.Transparency = true, 0
    end
end

clickDetector.MouseClick:Connect(BuildBrick)

Notice the additional check. That is because MouseClick can fire even if it was not the local player! The code in the if will not execute if the local player does not click the part.

7 comments

0

Could you help me out with that answer I posted? Or should I just respect it?

0

It worked! Really big thanks!

0

Also, how do I accept an answer?

0

You can't accept answers at 0 reputation.. Keep that in mind, incapaxx

0

wrong

1

no prob for the accept xd

0

xddd

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