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!
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)
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.