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

When a clickdetector is clicked is the player in Players effected or the players model?

Asked by 6 years ago

When someone clicks a click detector does the click detector react to the player in "Players" or in the players model in workspace?

Like when you're doing ontouched and you put

function onTouched(hit)

the 'hit' is the player model but when I do the same with OnClicked does the hit mean the player in 'Players' or the players model?

2 answers

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

The "player model" you're referring to is more fittingly called the Character. The Touched event's only parameter is the part that touched. This means that, if a player's character touches it, the character model will be part.Parent. These are examples with :GetFullName(), which returns a string displaying the object's ancestory.

local part = workspace.Part

part.Touched:Connect(function(otherPart)
   print(otherPart:GetFullName()) --will print something like "game.workspace.gioni01.Torso"
end)

The MouseClick event of ClickDetectors has one parameter: the player who clicked (the object in the Players service, as you said).

local part = workspace.Part
local ClickDetector = part.ClickDetector

ClickDetector.MouseClick:Connect(function(player)
   print(player:GetFullName()) --> prints "game.Players.gioni01"
end)

Don't be discouraged when you're not sure of the parameters of an event. Short of guessing, you simply cannot know until you search them on the wiki!

Resources:

:GetFullName()

Touched

MouseClick


Accept and upvote if this helps!

Ad
Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

"the 'hit' is the player model but when I do the same with OnClicked does the hit mean the player in 'Players' or the players model?"

hit is not the player's model. In Touched events, that is the parameter passed to your event listener, which is the other part that touches the part. It doesn't have to be named hit; it is merely convention to name it like that, as it is the part that hit your brick. If a player touches a part, it is a body part from their character, for example the left foot. It does not have to be the player either. Anything can touch other parts.

"When a clickdetector is clicked is the player in Players effected or the players model?"

This is not a very meaningful question, as it depends on what the event listener of the ClickDetector event does.

Answer this question