I'm trying to make a tool that when equipped and clicked on a player, the player will switch teams. So far, I've looked into the API:Class/Tool section of the wiki, but nothing to be found there. I then checked out The API:Class/PlayerMouse and saw the 'BasePart Target' property, 'GetNetworkOwner()' function, and 'IsA()' function. I've thought about using the BasePart property to find the parent of the target, then see if humanoid belonged to the target, but I haven't seen anything about the parent of a target in the properties category of the API:Class/BasePart page. I was thinking about doing a similar thing with the IsA() function, by checking if the object that was clicked on is a part, getting the parent, seeing if there was a humanoid, then continuing with the code. I'm not exactly clear on what the GetNetworkOwner function does, as there isn't much on it in the wiki, but maybe using that to get the parent of the object clicked on as well? I was hoping to receive some enlightenment as to how I would go about getting the player/checking if it was a player that the player holding the tool clicked on, and how I would go about using the functions. Thank you for any and all help!
GetNetworkOwner is irrelevant. What you want to do is really easy.
mouse.Target is the part the player is looking at. Once you know this, you can check to see if the target is of a character.
local player = game.Players.LocalPlayer local mouse = player:GetMouse() mouse.Button1Down:connect(function() --mouse clicked local part = mouse.Target --part the mouse is pointing at if part then local char = part.Parent local player= game.Players:GetPlayerFromCharacter(char) if player then --found player from part game.Players.LocalPlayer.Team = player.Team end end end