local maidClass = Maid.new()
local Debounce = false
local function GolemnHit(hitPart)
if Debounce or not hitPart.Parent:FindFirstChild("Humanoid") then return end
debounce = true
hitPart.Parent.Humanoid:TakeDamage(5)
wait(5)
Humanoid.WalkSpeed = 16
maidClass:DoCleaning()
debounce = false
return
end
for _,Part in ipairs(Golem:GetDescendants()) do
if not Part:IsA("BasePart") then return end
maidClass:GiveTask(Part.Touched:Connect(GolemnHit))
end
I am making a boss fight where the boss charges on the player and damage it on touch. My boss should only damage it once, but here itâs damaging the player over 10 times, wich is too much (I set 5 to see how much is the boss damaging, and it spam attacks, leaves the player with only 50 HP, then dosenât waits 5 seconds but starts again to attack, wich kills the player in 3 seconds).
I added a debounce to the function, but it dosenât seem to works, because even if the debounce is true and that it should stop, it just ignores it. Whatâs the problem? I need to deconnect the event to make it stops damaging the player, so I am using Maids, but it isnât deconnecting, wich confuses me.
I tried it, but apparently Maids are better. And they use the Disconnect function:
But thanks for trying! My problem is that in the line with maidClass:DoCleaning() the Event should disconnect (If I understod maids enough), but it isnât working. If I would use the Disconnect function, I would have a code over 40 lines, wich I had but was a true mess.
I have used maids before and Iâm pretty sure they disconnect, I believe the problem here is the order at which the lines are running within the function relative to the yield.
local Debounce = false
local function GolemnHit(hitPart)
if Debounce or not hitPart.Parent:FindFirstChild("Humanoid") then return end
Debounce = true --missed a capitalization here
hitPart.Parent.Humanoid:TakeDamage(5)
Humanoid.WalkSpeed = 16
maidClass:DoCleaning()
wait(5)
Debounce = false
return
end
The disconnect should be happening immediately if you want to prevent the previous connections from occurring. Also I believe there is a mispelling with the debounce as it should be capitalized according to the debounce variable so yeah it may trigger multiple times in a row.
@dthecoolest, I checked my Code and I wrote the same only everything in lowletters, so I tested the game and no, the bug is still running. Nothing changed, so I donât think it disconnected.
Ok, I started printing this whole line out, to see if it was true or false, and it was false. Now I finally have a. Way to check. It turns out that both of them are false. I would understand that not hitPart.Parent:FindFirstChild("Humanoid") is false, because the player is still alive, but the debounce should be true. And if I print it out, it isnât! It changes to true, but when the next touched event is fired, it tourns to false. So, the debounce isnât updating, but why? Is it because this function is local?
Edit: No, even change the function to a global function, the result is the same: The debounce variable changes to true only while the event is running, after this it gets false. And when the debounce is false then the loop dosenât stop.
I think that the problem is because your giving each individual part inside of the golem the touch connection so the player gets damaged multiple times.
Itâs normal, because I canât predict what part accurately touches the player, so while the boss is charging, every part does damage. But after the damage is done the event needs to be disconnected to avoid that the other parts do damage too.
But the maid isnât deconnecting, this means that the event still runns, wich means that it still damages the player.
What do you mean? I want to keep it accurate, so I made that every part of the golem becomes deadly. I am testing this on a normal R15 dummy before trying this to a custom character and no, I didnât add something extra to the dummy.
Edit: I tried to make that after the damage it disconnect all connections, and it dosenât work.
Oh, so thats how you want it. I dont really know how to disconnect all the connections on every part that has one once a certain thing happens. I would usually go with making an individual part that scales as big as the model with a touch event.
Oh, then I think you best option is ask other people for help or look at the developer Hub for more information on this. I think others can find a better answer to your question than me.
But, I really donât understand why a connection isnât disconnecting, I worked some weeks ago on another thing where I needed to disconnect an event, it showed me that the event was disconnected, but it didnât helped me out. I tried yesterday with math, wich âworkedâ, but even if you dodge it it did you damage because It was like a hitbox (and the code was too long)
What I am trying to say is that why event disconnecting dosenât work when I try them?
I donât think I know a way to disconnect all existing connections on the models parts using maid class. Also sorry for not telling you in advanced that I donât really know how to use Maids.
Probably the problem is âwait(5)â which yields the thread that launched the event, allowing it to run more than once. Debounce is also not working because of a spelling error. If you disconnect the event immediately, you donât need to debounce and the event thread will only run once.
local function GolemnHit(hitPart)
if not hitPart.Parent:FindFirstChild("Humanoid") then return end
maidClass:DoCleaning()
hitPart.Parent.Humanoid:TakeDamage(5)
maidClass:DoCleaning()
wait(5)
Humanoid.WalkSpeed = 16
return
end
Keep in mind that you are disconnecting all touch events at the same time and not just the event that was fired.
After trying to solve it, I am seeing that the problem is the debounce variable. Like I suspected, after the Event is done it turns from true to false, wich allows the loop to be played again. I canât understand why. And no, I tried this and it dosenât solve the problem. I will try to continue to dig, maybe I should first remove maids.
This is why debounce needs to stop the damage while itâs disconnecting everything.