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:
local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local kind = "Name" local char = game.Workspace:FindFirstChild(plr.Name) mouse.Button1Down:connect(function() if mouse.Target ~= nil then if kind == "Name" then local g = mouse.Target.Parent if g:FindFirstChild("Humanoid") then -- Where I am stuck on end end end end)
local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local kind = "Name" local char = game.Workspace:FindFirstChild(plr.Name) mouse.Button1Down:connect(function() if mouse.Target ~= nil then if kind == "Name" then local g = mouse.Target.Parent if g:FindFirstChild("Humanoid") then print(g.Name) --prints the name of the parent, aka the player end end end 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.
local mouse = player:GetMouse{} local plr = game.Players:GetPlayers() mouse.Button1Down:Connect(function() for i, v in pairs(plr) do --loops through the players in a server and checks if it is equal to the target parent if mouse.Target.Parent == v then print(v) else --ignores result end end end)
I believe this works, but I have heard that mouse.Target doesn't work on players, but try this.