I’m not sure why but the “if debounce then return” line isn’t working after the hyperArmorEvent has been fired. I’m trying to make it so that the debounce will be true.
local debounce = false
hyperArmorEvent.OnServerEvent:Connect(function()
debounce = true
end)
notBlockingEvent.OnServerEvent:Connect(function()
debounce = false
end)
if debounce then return end
print(debounce)
Note that the lines with hyperArmorEvent and notBlockingEvent are only connecting some function to the events. After that connection has been made, the script continues executing the next lines. As a result, the if statement runs only once when the script is executed.
You can fix this by putting the if statement inside each event callback function separately.
hyperArmorEvent.OnServerEvent:Connect(function()
debounce = true
if debounce then return end
end)
notBlockingEvent.OnServerEvent:Connect(function()
debounce = false
if debounce then return end
end)
Ok, I just tried it, I’m not sure if the rest of my script is affecting my debounce value but the debounce still doesn’t work. Here’s my script:
local debounce = false
if debounce then return end
hyperArmorEvent.OnServerEvent:Connect(function()
debounce = true
end)
notBlockingEvent.OnServerEvent:Connect(function()
debounce = false
end)
That’s not quite the right place for the debounce check. Here’s where it should be:
local debounce = false
hyperArmorEvent.OnServerEvent:Connect(function()
if debounce then return end
debounce = true
end)
notBlockingEvent.OnServerEvent:Connect(function()
if debounce then return end
debounce = false
end)
Idk why, but it’s still not working. I’ll show the full script just in case, it’s a burn system:
local debounce = false
local hyperArmorEvent = game.ReplicatedStorage.BlockSystem:WaitForChild("Hyperarmor")
local notBlockingEvent = game.ReplicatedStorage.BlockSystem:WaitForChild("NotBlocking")
local burndmg = 3
local isBurning = false
hyperArmorEvent.OnServerEvent:Connect(function()
if debounce then return end
debounce = true
end)
notBlockingEvent.OnServerEvent:Connect(function()
if debounce then return end
debounce = false
end)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.ChildAdded:Connect(function(child)
if child.Name == "BurnEffect" then
if character.HumanoidRootPart:FindFirstChild("Fire") then
return
end
isBurning = true
game.ReplicatedStorage.StunStart:FireClient(player)
local fire = Instance.new("Fire")
fire.Size = 10
fire.Parent = character.HumanoidRootPart
while isBurning == true do
wait(1)
humanoid:TakeDamage(burndmg)
local Tagged = Instance.new("ObjectValue")
Tagged.Name = "killer"
Tagged.Value = player
Tagged.Parent = humanoid
game.Debris:AddItem(Tagged,2)
end
fire:Destroy()
end
end)
humanoid.ChildRemoved:Connect(function(childremoved)
if humanoid:FindFirstChild("BurnEffect") then
isBurning = true
else
isBurning = false
end
end)
end)
end)
Anything outside a function block will only run once. Your second line would no longer execute again until you restart your Script (via disabling and reenabling it).
Not sure how you would use the debounce, but this is how I would approach a debounce, I guess.
local debounce = false
function action()
if debounce then return end
-- insert other code here.
end
hyperArmorEvent.OnServerEvent:Connect(function()
debounce = true
action() -- If debounce == false, runs function. Otherwise "action()" rejects running the same code again, until debounce is false.
end)
notBlockingEvent.OnServerEvent:Connect(function()
debounce = false
end)
If you will loop a set of instructions when action() is called, make sure the loop also checks if debounce is false.
function action()
if debounce then return end
while debounce do
task.wait() -- to prevent freezing.
-- your code.
end
end
Finally, if you want action() to disable the debounce by itself upon completing its course, add debounce = false at the end.
Thanks, but right now I’m trying to make it so that the burn system runs passively until debounce equals false. I think in your case, the burn system will only run after the hyperArmorEvent fires.
If my guess is right, you want the fire magic to burn the player if debounce is false and activate the debounce? Then, if the debounce is true, you want other projectile hits to not inflict burning (debuff?) when the debounce is still true?
If so, the same idea can be used without the action() function. You can check if debounce is true in the humanoid.ChildAdded:Connect(function(child) ... end) end function.
From your previous post, you might just want the debounce test like this:
humanoid.ChildAdded:Connect(function(child)
-- The following line below should stop a second call while debounce is active.
if debounce then return end -- <=======
if child.Name == "BurnEffect" then
if character.HumanoidRootPart:FindFirstChild("Fire") then
retu...
local HyberArmorDebounce = {}
local notBlockingDebounce = {}
hyperArmorEvent.OnServerEvent:Connect(function(Player)
if HyberArmorDebounce[Player] then return end
HyberArmorDebounce[Player] = true
wait() -- Make Cooldown if you want
HyberArmorDebounce[Player] = nil
end)
notBlockingEvent.OnServerEvent:Connect(function(Player)
if notBlockingDebounce[Player] then return end
notBlockingDebounce[Player] = true
wait() -- Make Cooldown if you want
notBlockingDebounce[Player] = nil
end)
So basically what you can do is make a table for each event you have, Insert the player into the index so everyone has there own unique debounce and set it too true and after the cooldown set it too nil
Thank you for all the suggestions, the debounces could work that way too. I just realized that all I had to do was add the debounce after the child function:
local debounce = false
local hyperArmorEvent = game.ReplicatedStorage.BlockSystem:WaitForChild("Hyperarmor")
local notBlockingEvent = game.ReplicatedStorage.BlockSystem:WaitForChild("NotBlocking")
local effect
local burndmg = 3
local isBurning = false
hyperArmorEvent.OnServerEvent:Connect(function()
debounce = true
end)
notBlockingEvent.OnServerEvent:Connect(function()
debounce = false
end)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.ChildAdded:Connect(function(child)
if child.Name == "BurnEffect" then
if debounce then return end
if character.HumanoidRootPart:FindFirstChild("Fire") then
return
end
isBurning = true
game.ReplicatedStorage.StunStart:FireClient(player)
local fire = Instance.new("Fire")
fire.Size = 10
fire.Parent = character.HumanoidRootPart
while isBurning == true do
wait(1)
humanoid:TakeDamage(burndmg)
local Tagged = Instance.new("ObjectValue")
Tagged.Name = "killer"
Tagged.Value = player
Tagged.Parent = humanoid
game.Debris:AddItem(Tagged,2)
end
fire:Destroy()
end
end)
humanoid.ChildRemoved:Connect(function(childremoved)
if humanoid:FindFirstChild("BurnEffect") then
isBurning = true
else
isBurning = false
end
end)
end)
end)