So I have a punching tool, it works and all but the 2nd animation plays by itself when clicked once.
Though it’s supposed to click twice to play the 2nd animation
(Debounces are broken I don’t know why).
Code:
-- Services
local rp = game:GetService("ReplicatedStorage")
-- Variables
local pl = game:GetService("Players")
local lp = pl.LocalPlayer
lp.CharacterAdded:Wait()
local cr = lp.Character
local humanoid = cr:WaitForChild("Humanoid")
local tl = script.Parent
local remotes = rp:WaitForChild("remotes")
local events = remotes:WaitForChild("events")
local attack = events:WaitForChild("attack")
local anims = tl:WaitForChild("Anims")
local punch1 = humanoid:LoadAnimation(anims:WaitForChild("Punch1"))
local punch2 = humanoid:LoadAnimation(anims:WaitForChild("Punch2"))
local punchnumber = 1
local punched = false
-- Functions
function toolActivated()
if punched == false then
if punchnumber == 1 then
punchnumber = 2
punched = true
cr:WaitForChild("Animate").Parent = rp
punch1:Play()
attack:FireServer(1)
spawn(function()
wait(0.5)
rp:WaitForChild("Animate").Parent = cr
end)
wait(1)
punched = false
end
if punchnumber == 2 then
punchnumber = 1
punched = true
cr:WaitForChild("Animate").Parent = rp
punch2:Play()
attack:FireServer(2)
spawn(function()
wait(0.5)
rp:WaitForChild("Animate").Parent = cr
end)
wait(1)
punched = false
end
end
end
-- Events
tl.Activated:Connect(toolActivated)