Skip to content

Commit 5a05b53

Browse files
committed
feat: Add ToolUtils.getEquippedHumanoid() and ToolUtils.getEquippedPlayer()
1 parent e884c2e commit 5a05b53

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--[=[
2+
@class ToolUtils
3+
]=]
4+
5+
local require = require(script.Parent.loader).load(script)
6+
7+
local CharacterUtils = require("CharacterUtils")
8+
9+
local ToolUtils = {}
10+
11+
--[=[
12+
Gets the equipped humanoid for a given tool
13+
]=]
14+
function ToolUtils.getEquippedHumanoid(tool: Tool): Humanoid?
15+
assert(typeof(tool) == "Instance", "Bad tool")
16+
17+
local character = tool.Parent
18+
if not (character and character:IsA("Model")) then
19+
return nil
20+
end
21+
22+
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
23+
if not humanoid then
24+
return nil
25+
end
26+
27+
return humanoid
28+
end
29+
30+
--[=[
31+
Gets the equipped player for a given tool
32+
]=]
33+
function ToolUtils.getEquippedPlayer(tool: Tool): Player?
34+
assert(typeof(tool) == "Instance", "Bad tool")
35+
36+
local humanoid = ToolUtils.getEquippedHumanoid(tool)
37+
if not humanoid then
38+
return nil
39+
end
40+
41+
return CharacterUtils.getPlayerFromCharacter(humanoid)
42+
end
43+
44+
return ToolUtils

0 commit comments

Comments
 (0)