What I am trying to do here is when you click a players Torso/Humanoid, it will print out there username. But I can't find or even create the right function for it. Any help? (Also I probably messed up on some of the functions so if I did then please fix it thank you.)
code:
01 | local plr = game.Players.LocalPlayer |
02 | local mouse = plr:GetMouse() |
03 | local kind = "Name" |
04 | local char = game.Workspace:FindFirstChild(plr.Name) |
05 |
06 | mouse.Button 1 Down:connect( function () |
07 | if mouse.Target ~ = nil then |
08 | if kind = = "Name" then |
09 | local g = mouse.Target.Parent |
10 | if g:FindFirstChild( "Humanoid" ) then |
11 | -- Where I am stuck on |
12 | end |
13 | end |
14 | end |
15 | end ) |
01 | local plr = game.Players.LocalPlayer |
02 | local mouse = plr:GetMouse() |
03 | local kind = "Name" |
04 | local char = game.Workspace:FindFirstChild(plr.Name) |
05 |
06 | mouse.Button 1 Down:connect( function () |
07 | if mouse.Target ~ = nil then |
08 | if kind = = "Name" then |
09 | local g = mouse.Target.Parent |
10 | if g:FindFirstChild( "Humanoid" ) then |
11 | print (g.Name) --prints the name of the parent, aka the player |
12 | end |
13 | end |
14 | end |
15 | end ) |
So in all honesty your code works fine. If you were testing it on yourself in studio then that would be where the error occurred for you as it wont work on the player who is clicking.
Side note: In order to test things like this when you are developing by yourself there is a feature in roblox studio under test which is called clients and servers and it allows you to test as multiple players as once.
01 | local mouse = player:GetMouse { } |
02 | local plr = game.Players:GetPlayers() |
03 |
04 | mouse.Button 1 Down:Connect( function () |
05 | for i, v in pairs (plr) do --loops through the players in a server and checks if it is equal to the target parent |
06 | if mouse.Target.Parent = = v then |
07 | print (v) |
08 | else |
09 | --ignores result |
10 | end |
11 | end |
12 | end ) |
I believe this works, but I have heard that mouse.Target doesn't work on players, but try this.