Hello there, I have a question about what I am doing wrong.
So AmouseClick() is a function that compares Mouse.Target and the humanoid's torso's distance between eachother. It says that if the distance is less than the range it would cause damage to Mouse.Target.Parent.Humanoid
My problem however is that I add debounce in a way different from yours, Instead I disconnect the event nested in the function as highlighted with a comment.
No errors, does not disconnect at all, (tried removing the reconnecting part and still doesn't disconnect) and just let's the player spam their mouse.
The debounce is running once. I'm not fully sure of how to debounce since I'm not sure if events still do listen while a wait() is yielding the script. Just think of it has people walking into a door closed, won't they still walk in once the door is open?
Note: variable mouseEvent is stated before this function and is assigned an event after this function.
local function AmouseClick()
if Settings.Class == nil then
return nil
end
print("Mouse Clicked")
if not debounce then
if player.Team == game.Teams.Zombies then
if mouse.Target.Parent:FindFirstChild("Player") then
local targetPlayer = game.Players:GetPlayerFromCharacter(mouse.Target.Parent)
if targetPlayer.Team == game.Teams.Survivors then
local distance = (character.HumanoidRootPart.Position - mouse.Target.Position).Magnitude
if distance < Settings.Range then
local humanoid = mouse.Target.Parent.Humanoid
humanoid:TakeDamage(Settings.Damage)
end
end
end
end
debounce = true
else
print("Disconnecting mouse event") --This is the problem
mouseEvent:Disconnect()
wait(Settings.AttackTime)
mouseEvent = mouse.Button1Down:Connect(AmouseClick)
end
end
mouse.Button1Down:Connect(AmouseClick)
Thank you for viewing this!

1 comment
Is there no output whatsoever or is it printing "Disconnecting mouse event". Another thing, the debounce should be set true before doing all the checks to make sure that someone can't sneak in more than one click. Last thing, is debounce ever set back to false?