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

How do I find a players name and team they're in by using a tool and clicking on them?

Asked by 6 years ago

So, I'm making a tool and I'm trying to figure out how to get a players name and what team they're in

How the tool works is you would click the person you want to scan and it will display their name and depending on what team they are in it will display a certain message

The whole displaying bit I can do I just want some help with the whole finding player and all that.

Thanks

0
script plz User#23365 30 — 6y
0
There is no script, that's why I'm asking how it can be done TheBlue_Hood -5 — 6y

1 answer

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

you can use the Button1Down event of the players mouse and use a generic for loop to loop through all the players and check if the target is them.

ex

--client

local player = game.Players.LocalPlayer
local tool = script.Parent -- lets say this was the tool

tool.Equipped:Connect(function(mouse) 
    mouse.Button1Down:Connect(function() -- when the players clicks then
        if mouse.Target then
            for _,v in pairs(game.Players:GetPlayers()) do -- literate through all the players
                if mouse.Target.Parent == v.Character then
                    print(v.Name, v.TeamColor) -- prints the name and teamcolour of the player
                    break -- breaks the loop
                end
            end
        end
    end)
end)
0
also it doesnt work on ur own character User#23365 30 — 6y
0
See below for updated code TheBlue_Hood -5 — 6y
Ad

Answer this question