Hello, thanks for visting this forum
I am a very inexperienced scripter and I need assistance in my script. I wanna know if the Touched event is consistant for things like this.
What’s the problem ?
My problem is that whenever my hitboxes hits a player, the ‘for i loop’ (creating multiple hitboxes at once) does not break, as for the Rigs/NPCS, it always does.
The problem happens with 1 module triggering another module.
Here’s the Ability module:
local module = {}
local sss = game:GetService(“ServerScriptService”)
local killers = require(script.Killers)
local survivors = require(script.Survivors)
local hitbox = require(sss.Modules.HitboxModule)
function module.playAbility(role, ability, killer, plr)
if not role and ability and killer and plr then
return
end
if role == "Killer" then
local kl = killers[killer]
local ab = kl[ability]
if ab and kl then
task.wait(ab.Windup)
if ability == "Swing" then
for i = 1, ab.Hitboxcount do
local hit = false
hitbox.hitbox(plr.Character, 0.25, ab.Damage, ab.Hitboxsize, plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-5), function(victim)
hit = true
end)
task.wait(ab.Hitboxseconds)
print("hitbox")
if hit then
print("stopped")
break
end
end
end
end
else
end
end
return module
Now, here’s the Hitbox module:
local module = {}
local debris = game:GetService(“Debris”)
local listedVictims = {}
function module.hitbox(char, lifetime, damage, size, cframe, detected)
local active = true
local hitbox = Instance.new(“Part”)
hitbox.Parent = workspace
hitbox.CanCollide = false
hitbox.Massless = true
hitbox.Anchored = true
hitbox.Size = size
hitbox.CFrame = cframe
hitbox.CastShadow = false
hitbox.Transparency = 0.5
hitbox.Material = Enum.Material.ForceField
hitbox.BrickColor = BrickColor.new("Really red")
task.spawn(function()
task.wait(lifetime)
active = false
game:GetService("Debris"):AddItem(hitbox, 1.5)
end)
listedVictims = {}
hitbox.Touched:Connect(function(hit)
local victim = hit:FindFirstAncestorWhichIsA("Model")
if not victim then return end
if hit.Name ~= "HumanoidRootPart" then
return
end
local vhum = victim:FindFirstChildOfClass("Humanoid")
if not vhum then return end
if not active then
return
end
if victim == char or listedVictims[victim] then return end
listedVictims[victim] = true
print(hit.Name, victim)
vhum:TakeDamage(damage)
hitbox.BrickColor = BrickColor.new("Lime green")
if detected then
detected(victim)
else
print("no detected")
end
active = false
end)
end
return module
Any help is very veryyy appreciated, I took a long time to try to fix this but no solution.