Hello! I’m having an issue with my script where I need to check for if an attribute changes but whenever any attribute changes it will create this error and then crash the server. Does anyone know what this error means?
Error : Maximum event re-entrancy depth exceeded for Instance.AttributeChanged
Code Snippet of my function :
Monster.AttributeChanged:Connect(function(AttributeName)
if Monster:GetAttribute("AntiStun") == true and AttributeName == "Hit" and Monster:GetAttribute("Hit") ~= 0 then
Monster:SetAttribute("Hit",0)
end
end)
Any help would be appreciated, thank you in advance
How would I go about this? I have tried using a simple debounce with a boolean variable and still am encountering the same issue.
local Debounce = false
Monster.AttributeChanged:Connect(function(AttributeName)
if Debounce ==false then
if Monster:GetAttribute("AntiStun") == true and AttributeName == "Hit" and Monster:GetAttribute("Hit") ~= 0 then
Monster:SetAttribute("Hit",0)
Debounce = true
task.wait(0.1)
Debounce = false
end
end
end)
local Debounce = false
Monster.AttributeChanged:Connect(function(AttributeName)
if Debounce then return end -- Stop running the thread
if Monster:GetAttribute("AntiStun") == true and AttributeName == "Hit" and Monster:GetAttribute("Hit") ~= 0 then
Debounce = true -- set it *before* you set the new value
Monster:SetAttribute("Hit",0)
task.wait(0.1)
Debounce = false
end
end)
local con
function AttributeChanged()
if Monster:GetAttribute("AntiStun") == true and AttributeName == "Hit" and Monster:GetAttribute("Hit") ~= 0 then
con:Disconnect()
Monster:SetAttribute("Hit",0)
con = Monster.AttributeChanged:Connect(AttributeChanged)
end
end
con = Monster.AttributeChanged:Connect(AttributeChanged)