I am using while loops for making a moving Region3, but I am making a magic game with a lot of projectiles and the Region3 as the hitbox. So I’m sure the while loops will start to lag the game. I looked in the Dev fourm and Youtube but found no solution. What are other ways to make a moving Region3 without a while loop?
Update the position parameters for the Region3.
I am already doing that with the while loop
Could you show me the while loop?
while windclone.Parent == workspace do
local regionpart = Instance.new(“Part”, workspace)
local region = Region3.new(Vector3.new(windclone.PrimaryPart.Position.X - (4), windclone.PrimaryPart.Position.Y + (4), windclone.PrimaryPart.Position.Z + (4)), Vector3.new(windclone.PrimaryPart.Position.X + (4), windclone.PrimaryPart.Position.Y - (4), windclone.PrimaryPart.Position.Z - (4)))
local partinregion = workspace:FindPartsInRegion3WithIgnoreList(region, char:GetChildren(), 1000)
regionpart.Anchored = true
regionpart.Name = "RegionPART"
regionpart.Transparency = 0.4
regionpart.BrickColor = BrickColor.new("Royal purple")
regionpart.Size = region.Size
regionpart.CFrame = region.CFrame
game.Debris:AddItem(regionpart, 0.1)
for i, v in pairs(partinregion) do
print(v.Name)
end
wait(0.1)
end
consider using the stepped event instead of wait()
documentation: RunService | Roblox Creator Documentation
Is the RunService.Stepped laggy?
I don’t think you moved the windclone? Unless you didn’t include that part or I am seeing it wrong.
Im not sure what you mean by moved windclone, and im sorry, I dont know how to make scripts easy to read on the Dev Fourm
Every time the loop runs the Region3 is based off of the windclone.PrimaryPart position which doesn’t get moved at all in the loop, which means the Region3 would stay in the same place the whole time.
What I am doing is recreating the region3 in the while loop, and setting its position on to the projectile.
From what I see the projectile doesn’t move at all, is this intentional or is it somewhere else in the code?
Somewhere else in the code, the projectile has a body velocity in it
Also to clarify this current code spawns in the Region3's at the projectile everytime, but you just want to use 1 Region3 over and over?
Yes the Region3 spawns at the projectile everytime. But what I want is to use something other than a loop to do this. Because whileloops are laggy is there are too much.
For a loop I would use RunService.Heartbeart, it is way better than a while loop in my opinion. I also will try and find a way to move a Region3.
Is it possible to move a Region3’s CFrame? I have not tested it yet, just thought of it.
No, the only way to even consider moving it is moving the 2 corner points it uses to make a box to the next position, but I don’t know if you can do this with an already existing Region3 yet.
Yeah, I don’t believe you can move already existing Region3's.