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

Script not detecting clickdetector click! Can anyone help?

Asked by 4 years ago
Edited 4 years ago

I'm trying to make it so when you click a part it makes your camera watch the NPC (custom shape) but it won't detect the click

--[[
Workspace
    Model
        Humanoid
            Script (Move script, Global)
        Eye 1 (MeshPart)
            Torso (Weld)
        Eye 2 (MeshPart)
            Torso (Weld)
        Mouth( MeshPart)
            Torso (Weld)
        RootPart (Part)
            ClickDetector
                LocalScript (Script I'm talking about)
]]

script.Parent.MouseClick:Connect(function()
    print("Active") --Doesn't print
    workspace.CurrentCamera.CameraSubject = script.Parent.Parent.Parent
end)
0
What is your script parented to? bum5Br 97 — 4y
0
Click detector ArvidSilverlock 50 — 4y
0
If you use that LocaScript inside of Workspace then It can't run. Change the script parent to...StarterGui bostaffmanbulgaria1 89 — 4y
0
@bostaffmanbulgaria1 Not that kind of script, it's a local script for a click detector ArvidSilverlock 50 — 4y
View all comments (2 more)
0
It needs to be a Script not a localscript. royaltoe 5144 — 4y
0
script.Parent.MouseClick:Connect(function(playerWhoClicked) the player who clicked is passed implicitly as a parameter royaltoe 5144 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Okay, so here is what I assume is happening here.

You have a ClickDetector that is a descendant of Workspace. Parented to said ClickDetector is a LocalScript that has no actual client associated with it.

Well, the LocalScript is the problem. LocalScripts won't run if they don't have a client associated with them. The exception to this rule is a player's Character located in Workspace. Because the Character is associated with a player (aka a client), any LocalScript that is parented to that Character will run, but any LocalScript parented to an NPC will not.

Server communication with a player's camera is not acceptable because FilteringEnabled will prevent it from happening. In order to alter the player's camera, either a RemoteEvent or RemoteFunction should be used so that the ClickDetector on the server can communicate with the player that clicks on the ClickDetector.

You may have not known this before, but MouseClick passes a player argument when it fires, meaning that the first parameter given will have a userdata value that points to the player:

script.Parent.MouseClick:Connect(function(p) -- Variable p gains a player value; this variable will now refer to the player who clicked on the ClickDetector

Using the FireClient() function of a RemoteEvent or the InvokeClient() function of a RemoteFunction, you can communicate with the player passed by MouseClick:

-- Option 1
event:FireClient(p) -- Fires a signal to p, the player passed by MouseClick
-- Option 2
func:InvokeClient(p) -- Yields for p, meaning that it will wait until the client fires OnClientInvoke
0
Nice explanation! Luka_Gaming07 534 — 4y
0
Thanks, this does work however it doesn't set the camera but at least now it prints! ArvidSilverlock 50 — 4y
Ad

Answer this question