I want to know how I can prevent too many loops and make it so I don’t have to loop through the games workspace every time a player wants to slash for my magnitude hotbox system.
Code:
for i,v in pairs(game.Workspace:GetChildren()) do
if v:FindFirstChild("Humanoid") then
local enemyHrp = v:FindFirstChild("HumanoidRootPart")
if (RootPart.Position-enemyHrp.Position).Magnitude <= Range and v.Name ~= name then
local hum = v:FindFirstChild("Humanoid")
hum:TakeDamage(Damage)
end
end
end
ayoub50
(Ayoub)
August 2, 2022, 5:50pm
#2
put the script in StarterCharacterScripts instead.
the Player Character Will be The Parent
Dervex
(Dervex)
August 2, 2022, 5:50pm
#3
What about using Region3 s?
you could add the players character to a folder in workspace and loop through the folder
I believe Region3 is mostly Deprecated, newer solution would be Overlap Params
joso555
(joso555)
August 2, 2022, 5:51pm
#6
if u want to find an specific object with no looping this is a method:
instace:FindFirstChild("idk", true)
Eh. Im not interested in raycasting or region3 or overlap params.
But you need to loop through all the player character instances in order to find if a character is in the hitbox
joso555
(joso555)
August 2, 2022, 5:54pm
#9
ok so instead of that use get players so u dont loop all workspace
RC_R0BLOX
(byteRC)
August 2, 2022, 5:55pm
#10
GetPlayers() does not loop through the character objects, it only loops through player objects.
Can’t you grab the HRP and Enemy distance without looping through workspace, and if it isn’t in range you just return the script? (Bad english :D)
joso555
(joso555)
August 2, 2022, 5:55pm
#12
yeah but u dont understand the point bro u can loop by the player character with that method .__.
RC_R0BLOX
(byteRC)
August 2, 2022, 5:56pm
#13
yeah that’s my problem. Im trying to figure a way to do that
RC_R0BLOX
(byteRC)
August 2, 2022, 5:56pm
#14
Can you show a example of this?
joso555
(joso555)
August 2, 2022, 5:57pm
#16
that actually can have some error with rbx core scripts
then the best way is as you said GetPlayers()
joso555
(joso555)
August 2, 2022, 5:58pm
#18
yeah of course
for i, plr in pairs(game.Players:GetPlayers()) do
if plr.Character then
local Hrp = plr.Character.HumanoidRootPart
--doSomething
end
end
RC_R0BLOX
(byteRC)
August 2, 2022, 6:00pm
#19
Hmm… Let me try this new method.
Forummer
(Forummer)
August 2, 2022, 6:42pm
#20