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

The Click Detector not working (local model) ?

I have a click detector in my model and a script, when i click on the model it should print somthing but it does not print anything(there are no Errors or Warnings) , and it is because the model is local (only specific player can see it). Can anyone tell me how to solve the problem?

script code :

local clickDetector = script.Parent.ClickDetector
function onMouseClick(player)
	print(player.Name," clicked me!")
end
clickDetector.MouseClick:Connect(onMouseClick)

1 answer

✓ Accepted answer

Your code is fine, but your script needs to be a Script (server Script) not a LocalScript. If you have a LocalScript, you'll see the hand icon but no code will execute. Likewise, if you have a server Script and somehow accidentally set it Disabled, it will also not work. Other than that, you just need for there to be at least one Part in the model to have something to click.

EDIT: I added a comment below, since you changed your question after I wrote my answer. You should add an edit note like this one if you change your question after it has answers, as you just made it look like I ignored your question and wrote an incorrect answer :-/ Your original question had no mention of the Model being locally-created. You have no choice but to use a LocalScript in this case, but you can't just put it in the Model. LocalScripts won't execute in the Workspace.

1 comment

0

If you need a LocalScript to run code when the Model is clicked, the LocalScript can't be inside the model. It has to be in one of the places where LocalScripts can execute from (PlayerScripts, PlayerGui, etc.) and getting a reference to the Model and ClickDetector via a WaitForChild() call.

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