Making charged punch and I don't know what's wrong with the script

I am creating a punch tool that plays an animation on loop when you hold mouse1 and plays a punch animation when you release. I can’t tell what I did wrong with the script but I believe it has to do with lines 20-22.
image

local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

local humanoid = char:WaitForChild(“Humanoid”)

local Holding = script:WaitForChild(“Holding”)

local anim = script:WaitForChild(“Punch”)

local anim1 = script:WaitForChild(“PunchReady1”)

local anim2 = script:WaitForChild(“PunchLaunch”)

local anim3 = script:WaitForChild(“PunchHold”)

local Punchdo = humanoid:LoadAnimation(anim)

local PunchReady = humanoid:LoadAnimation(anim1)

local PunchLaunch = humanoid:LoadAnimation(anim2)

local PunchHold = humanoid:LoadAnimation(anim3)

script.Parent.Activated:Connect(function()

Holding.Value = true

PunchReady:Play()

if Holding == true then

PunchHold:Play()

end

end

script.Parent.Deactivated:Connect(function()

Holding.Value = false

PunchLaunch:Play()

end)

What exactly isn’t working with your script?

Not related to your issue necessarily but insie the Tool.Activated function you set Holding.Value to true and check two lines later if Holding == true. This isn’t necessary as you’ve already set it to true in the same block and know it’s value. You may also want to check if Holding.Value == true if you did as itll presumably always return true if Holding is a BoolValue.

My problem started when I added a second animation to tool.activated. When I activated the tool after that it wouldn’t play the animation. I don’t know how to play both of the animations.

So are you wanting to play PunchReady and then loop PunchHold until the player releases the mouse?

Maybe in the Activated function try:

Holding.Value = true
PunchReady:Play()
PunchReady.Stopped:Wait()
PunchHold:Play() --Make sure PunchHold is a looping animation

And in the Deactivated function:

Holding.Value = false
PunchHold:Stop()
PunchLaunch:Play()

Yes, this did solve my problem. Thank you.

1 Like