While the tool is activated and plays an animatiion, if the uppertorso or lowertorso is touched, then the enemy will take damage. There are no errors, and this works fine. The problem is, after the tool is activated, the uppertorso and lowertorso continue to deal damage on touch. Please fix this:
local tool = script.Parent
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://1119832753"
local debounce = false
local hit = false
tool.Activated:Connect(function()
if debounce == false then
debounce = true
print("The cheese has been clicked!")
local plr = game.Players.LocalPlayer.Character
local trackanimation = plr.Humanoid:LoadAnimation(animation)
local touchedConnection = plr["UpperTorso"].Touched:connect(onTouch)
local touchedConnection = plr["LowerTorso"].Touched:connect(onTouch)
trackanimation.KeyframeReached:Connect(function()
end)
--script.Parent.Parent.barfnow:FireServer()
trackanimation:Play()
wait(0.1)
script.Fart:Play()
wait(1.9)
debounce = false
end
end)
function onTouch(part)
if not hit and part.Parent:FindFirstChild("Humanoid") then
hit = true
local humanoid = part.Parent:FindFirstChild("Humanoid")
humanoid:TakeDamage(game.Players.LocalPlayer:FindFirstChild("leaderstats").Calories.Value)
wait(2)
hit = false
end
end

1 comment
[READ] Line 31 is humanoid:TakeDamage(game.Players.LocalPlayer:FindFirstChild("leaderstats").Calories.Value)