/
HumanoidUtils.lua
44 lines (37 loc) · 934 Bytes
/
HumanoidUtils.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
--[=[
General humanoid utility code.
@class HumanoidUtils
]=]
local HumanoidUtils = {}
--[=[
Retrieves a humanoid from a descendant.
@param descendant Instance -- Child of a humanoid model, like a limb
@return Humanoid?
]=]
function HumanoidUtils.getHumanoid(descendant)
local character = descendant
while character do
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
return humanoid
end
character = character:FindFirstAncestorOfClass("Model")
end
return nil
end
--[=[
Forcefully unseats the humanoid. Useful when teleporting humanoid.
Definitely a non-intuitive operation to do safely.
@param humanoid Humanoid
]=]
function HumanoidUtils.forceUnseatHumanoid(humanoid)
if humanoid.SeatPart then
local weld = humanoid.SeatPart:FindFirstChild("SeatWeld")
if weld then
weld:Destroy()
end
humanoid.SeatPart:Sit(nil)
end
humanoid.Sit = false
end
return HumanoidUtils