ClickDetector not working

Hi devs,
So I was trying to make a gui appear from a clickdetector. It didn’t work. To make sure its not my fault I did this:

script.Parent.MouseClick:Connect(function()
    print("hi")
end)

but nothing happened. I tried both in a LocalScript and a Script to no avail. Help would be appreciated.

1 Like

May I see your explorer and where the script is located in?

2021-05-26 (10)
its in a npc (the mouse icon also changes)

It may be because the LocalScript is not running. Could you try it with a normal script?

print("ran")
script.Parent.MouseClick:Connect(function()
    print("hi")
end)

Also are you sure you’re clicking the click detector?

yes, am sure am clicking it. testing.

LocalScripts don’t work in workspace.

even if its inside the clickdetector?

it did print that. ill test with the gui.

Nope, still wouldn’t work. It only works in StarterGui, StarterCharacterScripts, and StarterPlayerScripts.

2 Likes

Also, I don’t think you can put a clickdetector in a HumanoidRootPart. Put it in the torso instead.

Not to mention, but it works in replicated first as well.

Would be great if you guys are able to help me with it showing a gui. Am currently using this:


but it says an error:
Workspace.EcroMan.HumanoidRootPart.ClickDetector.Script:3: invalid argument #2 (string expected, got Instance)

1 Like

Instead of doing [player], do [player.Name], as player is the instance itself.

2 Likes

lemme test.
30 c-h-a-r-a-c-t-e-rs

Thanks @IndexSource it worked. Have a great day!

1 Like

I just did a test on it in Studio.

You can definitely use click detector inside of HumanoidRootPart (just really hard to click on it.) I strap a server script onto the click detector.

local CD = script.Parent;
local RE_GuiTrigger = game.ReplicatedStorage:WaitForChild("guiTrigger");


CD.MouseClick:Connect( function( plr )
	RE_GuiTrigger:FireClient( plr );
end)

For the GUI part. Gui are independent to the client, it would be weird to open everyone’s gui if you click on the person. :stuck_out_tongue:

So you need to use Remote Event to signal the player to open their Gui inside of the PlayerGui.

To capture the Remote Event, I put a local script inside of the StarterPlayerScripts

local PlayerGui = game.Players.LocalPlayer:WaitForChild( "PlayerGui" );
local screenGui = PlayerGui:WaitForChild( "ScreenGui" );

local RE_GuiTrigger = game.ReplicatedStorage:WaitForChild("guiTrigger");

RE_GuiTrigger.OnClientEvent:Connect( function( )
	screenGui.Enabled = not screenGui.Enabled;
end)

I hope this all makes sense. :slight_smile:

1 Like

it does, but am not opening everyone’s gui. as u can see i use the player parameter returned by the cd and open that players gui. I hope this also makes sense :grinning_face_with_smiling_eyes:

Also you will have to do exploiter checks if you use remote events.

1 Like

oh my god this post is 2 years old

1 Like

Put script as local script wont work but it actually have a way .
1 Put your script in StarterGUI so it can run on client (Player GUI)
2 Run your script
Example :

game.Workspace.*Your part*.MouseClick:Connect(function(player) -- local script is in StarterGUI
	print("Clicked")
end)

If you want it stay in workspace you can use Script instead of Local one so it can work on Server side,