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

What does the variable mean in this function? [Solved]

Asked by 6 years ago
Edited 6 years ago

I have a LocalScript in a ClickDetector which is in a part. In the LocalScript I have a function;

script.Parent.MouseClick:Connect(function()

end

If i understand correct, the word inside the brackets after function is a variable. I don't have a word there now but if I would have, what does it mean?

0
In this case it means players instance (client who clicked part) AswormeDorijan111 531 — 6y
0
Does that mean the player or the character? Spjureeedd 385 — 6y

1 answer

Log in to vote
1
Answered by
xPolarium 1388 Moderation Voter
6 years ago
Edited 6 years ago

MouseClick is an event that fires when a player clicks on the parent Part of the ClickDetector. It provides the player that clicked it as a parameter.

In form it would look like this:

local clickDetector = script.Parent

--Include the parameter
function onClicked(PlayerThatClicked)
    print(PlayerThatClicked.Name) --print's name of the player that clicked it.
end

--Connects to the function. Same as your code too
clickDetector.MouseClick:Connect(onClicked)

Not all events have a parameter that do the same thing. You could check by using the API reference in RobloxDev site.

All parameters, like a variable, can use any name inside the parenthesis.

Arguments and Parameter article

0
I believe you can just have PlayerThatClicked on line 5 without the .Name too. xPolarium 1388 — 6y
0
I did test with both .Name and without but nothing got printed Spjureeedd 385 — 6y
0
Make sure this is in a 'Script' and that the script is inside of a ClickDetector. The ClickDetector should also be inside of a part. xPolarium 1388 — 6y
0
I actually have a LocalScript in a ClickDetector which is in a part. Should I change to a normal script? Spjureeedd 385 — 6y
View all comments (4 more)
0
Thank you! I changed to a normal 'Script' and it worked!! Spjureeedd 385 — 6y
0
Yes. If you wanted the local script to detect the CD then you would need to put it in StarterPlayerScripts/StarterCharacter and then locate the part in workspace. A Script just makes it easier. xPolarium 1388 — 6y
0
I placed my script, the one in my question, in a script, and then I just wondered, in the brackets is it the player or the character? Spjureeedd 385 — 6y
0
It is the player (instance). xPolarium 1388 — 6y
Ad

Answer this question