Select a player by clicking on them with the tool equipped. I know of GetMouse(), but how do I actually make it detect and seek out the chosen player?
✓ ANSWER ACCEPTED
How do I choose a player using a tool?
1 answer
✓ Accepted answer
Use Mouse.Target to detect what the mouse is selecting. To get the Player, you can do...
local Mouse = game.Players.LocalPlayer:GetMouse()
if Mouse.Target.Parent:FindFirstChild('Humanoid') then
local Target = Mouse.Target
local Character = Target.Parent
local Player = game.Players:GetPlayerFromCharacter('Character')
end
Then you can use Tool Activated to use it
script.Parent.Activated:connect(function()
local Mouse = game.Players.LocalPlayer:GetMouse()
if Mouse.Target ~= nil then
if Mouse.Target.Parent:FindFirstChild('Humanoid') then
local Target = Mouse.Target
local Character = Target.Parent
local Player = game.Players:GetPlayerFromCharacter(Character)
end
end
end)
Put that in a local script and you might need a Handle inside the tool to activate.
This discussion is preserved as it was. New answers, comments, and votes are closed.
