add a variable to the function then check if that is in use!
game.Workspace.Part.ClickDetector.MouseClick:Connect(function(click)
if click then - alternativly you can use "While click" -- meaning when it is clicked do X
- code here!
end
end)
local Part = script.parent
local ClickDetector = Part:WaitForChild("ClickDetector")
ClickDetector.MouseClick:connect(function(MouseClick)
print("works")
end)
adding a waitforchild isn’t needed due to the fact we know its parented to the part so this would in tern slow the game down and is bad for the games performance!
it is much faster to use task.wait() as that is a built in function to the studio which is more upto date and has modern techniques to wait faster then the waitforchild which is primitive tech in this use case!
A “MouseClick” is considered as the mouse being pushed down and then released upon which the event fires. If you do not want this behaviour then a ClickDetector's MouseClick is not for you.
To get values from Server-Side you can use RemoteFunctions
Or continuously fire RemoteEvent to Server-Side.
(It’ll activate every time the player clicks Mouse Buttons, make an “if” check to avoid it.
Pass the values only when the mouse is at the certain part)