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

How do I choose a player using a tool?

Asked by 7 years ago

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?

1 answer

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

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.

Ad

Answer this question