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

How to find the Player's Model using an OnClicked Script?(Answered)

Asked by
RoJiyn 12
7 years ago
Edited 7 years ago

How to find Model of the Players.

--How To Find It
--for example
workspace.brick.MouseDectector.MouseClick:connect(function(playerwhoclick)
    --- This is where i got stuck.As stated in the question...Is it possible to find the model of the character who clicked the brick?
end)

Thanks!! btw,if you saw this question(that i post) before this post.I deleted the last post as i was unsure if i want to post it or not. Sorry!

3 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

As you appear to know, the playerwhoclick variable will hold the Player object of the player who clicked the brick.

Player objects have a property called Character which holds the player's model.

So, for example, this:

workspace.brick.MouseDetector.MouseClick:connect(function(playerwhoclick)
    local model = playerwhoclick.Character -- 'model' will be the player's model.
    if model then -- It is good practice to check if the player's character actually exists before doing anything with it.
        model.Humanoid:TakeDamage(50)
    end
end)

will deal 50 damage to whichever player clicked the brick.

(Also, I noticed you misspelled MouseDetector in your script. Might as well point it out now in case it's a problem)

0
Thanks RoJiyn 12 — 7y
Ad
Log in to vote
0
Answered by
movsb 242 Moderation Voter
7 years ago

I find it useful in cases when player.Character repeatively returns nil to simply make a variable for the players name and find it in the workspace using the :FindFirstChild() method like so:

game.Workspace.MouseDetector.MouseClick:connect(function(plr)
    local name = 
        plr.Name;
    local model = 
        game.Workspace:FindFirstChild(name);
end)

this works because the player model's name and the player's name are exactly the same.

0
Thanks RoJiyn 12 — 7y
Log in to vote
0
Answered by 7 years ago

The Model is the players Character property.

0
Thanks RoJiyn 12 — 7y

Answer this question