boom-bots/src/shared/client/ClientUtils/GetCharacter.luau
2026-05-02 23:53:49 +02:00

58 lines
1.2 KiB
Plaintext

local GetCharacter = {}
local localPlayer = game.Players.LocalPlayer
local RunService = game:GetService("RunService")
local childAddedEvent
local otherEvents = {}
function CharacterAdded(char : Model)
if childAddedEvent then
childAddedEvent:Disconnect()
childAddedEvent = nil
end
if otherEvents then
for i,v in pairs(otherEvents) do
v:Disconnect()
end
table.clear(otherEvents)
end
shared.Character = char
shared.Head = char:WaitForChild("Head")
shared.Humanoid = char:WaitForChild("Humanoid")
shared.HumanoidRootPart = char:WaitForChild("HumanoidRootPart")
--print(shared.HumanoidRootPart)
for i,v in pairs(char:GetDescendants()) do
--hidePart(v)
end
childAddedEvent = char.DescendantAdded:Connect(function(bodyPart)
--hidePart(bodyPart)
end)
end
function hidePart(bodyPart)
if (bodyPart:IsA('BasePart')) then
local event = bodyPart:GetPropertyChangedSignal('LocalTransparencyModifier'):Connect(function()
bodyPart.LocalTransparencyModifier = 1
end)
bodyPart.LocalTransparencyModifier = 1
table.insert(otherEvents,event)
end
end
function GetCharacter:Start()
CharacterAdded(localPlayer.Character or localPlayer.CharacterAdded:Wait())
localPlayer.CharacterAdded:Connect(CharacterAdded)
end
return GetCharacter