My problem is pretty simple, I’m trying to disconnect/stop a function while a wait() code is running under a function in a spawn() code. This is made to reset a combo of a melee combat system. It kind of works, however if the player clicks like every 0.5 seconds, the combo resets and the player can keep spamming and never end the combo, making it an ‘exploit’. This is my current code:
Remote.OnClientEvent:Connect(function(code,CD)
if code == "Light" then
spawn(function()
wait(CD + 1)
if Character:FindFirstChild("LightAttack") == nil then
lightCount = 1
end
end)
end
end)
I want it to stop the spawn(function() when a new “LightAttack” child is added to the character, so it stops counting to reset the combo. How would I go about it? I tried this:
Remote.OnClientEvent:Connect(function(code,CD)
if code == "Light" then
spawn(function()
Character.ChildAdded:Connect(function(child)
if child.Name == "LightAttack" then
return
end
end
wait(CD + 1)
if Character:FindFirstChild("LightAttack") == nil then
lightCount = 1
end
end)
end
end)
But nothing changes, as the ChildAdded event is, of course, being ignored or it’s simply returning itself. What’s a possible solution to this?