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)
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
.