@@ -13,15 +13,15 @@ local hitboxHandler = {
1313 hitboxTransparency = 0 ,
1414 hitboxCanCollide = false ,
1515 customPartName = " HeadHB" ,
16- hitboxPartList = {},
16+ hitboxPartList = {} :: { [ string ]: boolean } ,
1717
1818 ignoreTeammates = false ,
1919 ignoreFF = false ,
2020 ignoreSitting = false ,
2121 ignoreSelectedPlayers = false ,
22- ignorePlayerList = {},
22+ ignorePlayerList = {} :: { string } ,
2323 ignoreSelectedTeams = false ,
24- ignoreTeamList = {},
24+ ignoreTeamList = {} :: { string } ,
2525}
2626
2727type Entity = typeof (require (" ./Classes/Entity.lua" ).new (Instance .new (" Model" ))) & {
@@ -73,7 +73,7 @@ local function addEntity(entity: Entity)
7373 return if hitboxHandler .extendHitbox then hitboxHandler .hitboxCanCollide else value
7474 end ))
7575
76- -- properties don't trigger sethooks when set from a serverscript
76+ -- properties don't trigger sethooks when set by a serverscript
7777 partDumpster :dump (part .Changed :Connect (function (property )
7878 if partProperties .debounce then return end
7979 if partProperties [property ] then partProperties [property ] = part [property ] end
@@ -187,46 +187,57 @@ local function addEntity(entity: Entity)
187187 end
188188 end
189189
190- local function addUpdateEvents (character : Model ? )
191- -- print("addUpdateEvents:", entity:GetName(), character)
192- if not character then
193- -- print("character not found")
194- return
195- end
196- -- Roblox still hasn't fixed CharacterAdded firing before all of the limbs are loaded
190+ local function addUpdateEvents ()
191+ local character = entity :WaitForCharacter ()
192+ -- print("addUpdateEvents:", entity:GetName())
193+ -- Roblox still hasn't fixed CharacterAdded firing too early
197194 -- https://devforum.roblox.com/t/avatar-loading-event-ordering-improvements/269607
198195 local humanoid
199196 local loaded = false
200197 local startTime = tick ()
201198 while not loaded and tick () - startTime <= 2 do
202199 task .wait ()
203200 -- print("addUpdateEvents loop")
204- for name , _ in hitboxHandler .hitboxPartList do
205- -- print("checking part", name .. ":", character:FindFirstChild(name) ~= nil)
206- if not character :FindFirstChild (name ) then return end
207- end
201+ -- I sure hope limbs loading before the humanoid is consistent behavior! Seems fine in my 3 minutes of testing.
208202 humanoid = character :FindFirstChildWhichIsA (" Humanoid" )
209203 -- print("checking humanoid:", humanoid ~= nil)
210- if not humanoid then return end
204+ if not humanoid then continue end
211205 loaded = true
212206 end
213207 if humanoid then
208+ -- Have to check both Health and StateType since some games disable HumanoidStateType.Dead
209+ -- This has a side effect of calling hitboxStep twice on death for most games. Too bad!
214210 humanoid :GetPropertyChangedSignal (" Health" ):Connect (function ()
215- if humanoid .Health <= 0 then entity :hitboxStep () end
216- -- print(entity:GetName(), "died")
211+ if humanoid .Health <= 0 then
212+ -- print("0Health:", entity:GetName())
213+ entity :hitboxStep ()
214+ end
217215 end )
218216 humanoid .StateChanged :Connect (function (_ , newState )
219- if newState == Enum .HumanoidStateType .Dead then entity :hitboxStep () end
217+ if newState == Enum .HumanoidStateType .Dead then
218+ -- print("HumanoidDead:", entity:GetName())
219+ entity :hitboxStep ()
220+ end
220221 end )
221222 end
222- character .ChildAdded :Connect (function (child )
223- if child :IsA (" ForceField" ) then entity :hitboxStep () end
224- -- print(entity:GetName(), "invulnerable")
225- end )
226- character .ChildRemoved :Connect (function (child )
227- if child :IsA (" ForceField" ) then entity :hitboxStep () end
228- -- print(entity:GetName(), "vulnerable")
229- end )
223+ entity .dumpsters [character ] = Dumpster .new ()
224+ local characterConnectionsDumpster = entity .dumpsters [character ]
225+ characterConnectionsDumpster :dump (character .ChildAdded :Connect (function (child )
226+ if child :IsA (" ForceField" ) then
227+ -- print("+forcefield:", entity:GetName())
228+ entity :hitboxStep ()
229+ end
230+ end ))
231+ characterConnectionsDumpster :dump (character .ChildRemoved :Connect (function (child )
232+ if child :IsA (" ForceField" ) then
233+ -- print("-forcefield:", entity:GetName())
234+ entity :hitboxStep ()
235+ end
236+ end ))
237+ characterConnectionsDumpster :dump (character .AncestryChanged :Connect (function (_ , parent )
238+ if parent ~= nil then return end
239+ characterConnectionsDumpster :burn ()
240+ end ))
230241 entity :hitboxStep ()
231242 end
232243
@@ -240,7 +251,7 @@ local function addEntity(entity: Entity)
240251 playerConnectionDumpster :dump (player :GetPropertyChangedSignal (" Team" ):Connect (entity .hitboxStep ))
241252 end
242253
243- addUpdateEvents (entity : GetCharacter () )
254+ addUpdateEvents ()
244255end
245256local function removeEntity (entity : Entity )
246257 entity .oldProperties = {}
@@ -249,7 +260,7 @@ local function removeEntity(entity: Entity)
249260 end
250261end
251262
252- function hitboxHandler :updatePartList (list : { [ string] : boolean } )
263+ function hitboxHandler :updatePartList (list : { string } )
253264 hitboxHandler .hitboxPartList = {}
254265 local partMap : { [string ]: { string } } = {
255266 [" Custom Part" ] = { hitboxHandler .customPartName },
@@ -270,7 +281,7 @@ function hitboxHandler:updatePartList(list: { [string]: boolean })
270281 end
271282end
272283function hitboxHandler :updateHitbox ()
273- for _ , player in EntHandler :GetPlayers () do
284+ for _ , player : Entity in EntHandler :GetPlayers () do
274285 player :hitboxStep ()
275286 end
276287end
0 commit comments