While the blade is touching a object and the mouse is clicked the debounce fails to work.
It keeps ignoring line 1-38 and keeps playing the animation for a long time without waiting.
Why does it do this and how do I fix this?
LocalScript:
Player = game.Players.LocalPlayer
local Character = Player.Character
if not Character or Character.Parent == nil then
Character = Player.CharacterAdded:wait()
end
Tool = script.Parent
Blade = Tool.Blade
ClickedDebounce = false
---------------------------------------------------------------------
function CreateAnimation(id,Humanoid)
local AnimationName = "Animation_"..id
local FoundAnimation = Humanoid:FindFirstChild(AnimationName)
if not FoundAnimation then
local Animation = Instance.new("Animation",Humanoid)
Animation.Name = AnimationName
Animation.AnimationId = "http://www.roblox.com/Asset?ID="..id
return Animation
else return FoundAnimation
end
end
---------------------------------------------------------------------
Tool.Equipped:connect(function(Mouse)
print("Equipped")
Mouse.Button1Down:connect(function()
-----------------------------------
Blade.Touched:connect(function(TouchedPart)
local TouchedTarget = TouchedPart
local Target = Mouse.Target
if Target == TouchedTarget and TouchedTarget == Target then--Double sure the its the correct target
if ClickedDebounce == false then --if false then turn set it true
ClickedDebounce = true
wait(2)
local Humanoid = Character.Humanoid
local Animation = CreateAnimation("66332008",Humanoid)
local AnimationTrack = Humanoid:LoadAnimation(Animation)
AnimationTrack:Play()
ClickedDebounce = false
end
------------------------------------------
end
end)
end)
end)
