Hey everyone,
As the title states I’m currently trying to fix an issue in my game that involves debounce. I’ve made a fire spell that sends 1-5 bricks with fire particles out when it hits a target but the problem is that instead of spawning all the bricks at once it drip feeds them in like this
This is the debounce script I drafted up which is albeit a bit rough around the edges.
local debounce = false
function OnTouched(Part)
if Part.Parent ~= nil then
if debounce == false and Part.Parent:findFirstChild("Monster") ~= nil then
debounce = true
for i =1,5 do
local human = Part.Parent:findFirstChild("Monster")
local Splash = Instance.new("Part")
Splash.Parent = game.Workspace
Splash.Position = human.Torso.Position + Vector3.new(math.random(-5,5),math.random(-5,5),math.random(-5,5))
Splash.Shape = 1
Splash.formFactor = "Plate"
Splash.Name = "Splash"
Splash.BrickColor = BrickColor.new(26)
Splash.Transparency = 1
Splash.Size = Vector3.new(1,0.8,1)
Splash.Velocity = Vector3.new(math.random(-70, 70),math.random(-70, 70),math.random(-70, 70))
local Aura = script.Smoke:clone()
Aura.Parent = Splash
game:GetService("Debris"):AddItem(Splash, 3)
wait(0.3)
debounce = false
end
end
end
end
script.Parent.Touched:connect(OnTouched)
This is a clip of how I want it to behave but with less particles, hence the debounce since it appears to be hitting multiple times.
I’ve also posted the script without my attempts at adding debounce below.
local Pool = script.Parent
function onTouched(hit)
print("Pool hit")
local human = hit.Parent:findFirstChild("Monster")
if (human ~= nil ) then
for i =1,5 do
local Splash = Instance.new("Part")
Splash.Parent = game.Workspace
Splash.Position = human.Torso.Position + Vector3.new(math.random(-5,5),math.random(-5,5),math.random(-5,5))
Splash.Shape = 1
Splash.formFactor = "Plate"
Splash.Name = "Splash"
Splash.BrickColor = BrickColor.new(26)
Splash.Transparency = 1
Splash.Size = Vector3.new(1,0.8,1)
Splash.Velocity = Vector3.new(math.random(-70, 70),math.random(-70, 70),math.random(-70, 70))
local Aura = script.Smoke:clone()
Aura.Parent = Splash
game:GetService("Debris"):AddItem(Splash, 3)
end
end
end
script.Parent.Touched:connect(onTouched)
Any help would be appreciated, thanks!