Hello, I’m making a hitbox system that creates (clones) a certain number of parts when the player swings a sword. These parts are the hitbox. They’re are cloned every 0.05 seconds and are positioned and oriented to the sword’s blade.
I’ve already coded all the cloned part’s (hitbox’s) properties. It is created in a while true do
loop and I’m trying to figure out how to make the loop stop (stop the cloning) when a certain amount of clones have been created. (A remote event is fired to let the script know when to start and stop the cloning, which I’ve also already got set up). Just need it to stop the loop when a certain amount of clones have been created. Help is appreciated! Thanks.
P.S. I also want the clone’s CanTouch
property to be turned on for a split instant then turned off (to do damage).
My LocalScript (located in StarterCharacterScripts) that creates the hitboxes when remote is fired:
local Hitbox1 = script.Parent["Right Arm"].Handle.Holder.Blade.Hitbox1
local Hitbox2 = script.Parent["Left Arm"].Handle2.Holder.Blade.Hitbox2
local Debris = game:GetService("Debris")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DamageStart = ReplicatedStorage.DamageStart
local DamageEnd= ReplicatedStorage.DamageEnd
local BreakLoop = false
function StartHitboxes()
BreakLoop = false
while true do
task.wait(0.05)
if BreakLoop == true then
break
end
local Hitbox1Clone = Instance.new("Part", workspace)
local Hitbox2Clone = Instance.new("Part", workspace)
Hitbox1Clone.Name = "Hitbox"
Hitbox2Clone.Name = "Hitbox"
Hitbox1Clone.Size = Vector3.new(1.025, 1.46, 5.43)
Hitbox2Clone.Size = Vector3.new(1.025, 1.46, 5.43)
Hitbox1Clone.Anchored = true
Hitbox2Clone.Anchored = true
Hitbox1Clone.Transparency = 0.1
Hitbox2Clone.Transparency = 0.1
Hitbox1Clone.CanCollide = false
Hitbox2Clone.CanCollide = false
Hitbox1Clone.Material = Enum.Material.ForceField
Hitbox2Clone.Material = Enum.Material.ForceField
Hitbox1Clone.Color = Color3.new(1, 0, 0)
Hitbox2Clone.Color = Color3.new(1, 0, 0)
Hitbox1Clone.Massless = true
Hitbox2Clone.Massless = true
Hitbox1Clone.Position = Hitbox1.Position
Hitbox2Clone.Position = Hitbox2.Position
Hitbox1Clone.Orientation = Hitbox1.Orientation
Hitbox2Clone.Orientation = Hitbox2.Orientation
Hitbox1Clone.CanTouch = true
Hitbox2Clone.CanTouch = true
Hitbox1Clone.CanTouch = false
Hitbox2Clone.CanTouch = false
Debris:AddItem(Hitbox1Clone, 0.5)
Debris:AddItem(Hitbox2Clone, 0.5)
end
end
function StopHitboxes()
BreakLoop = true
end
DamageStart.OnClientEvent:Connect(function()
StartHitboxes()
end)
DamageEnd.OnClientEvent:Connect(function()
StopHitboxes()
end)