I am trying to make it when you have a tool, and activate it it plays a punching animation. But it doesn’t seem to play it, but no errors.
I have tried YouTube videos on how to play animations, didn’t work.
Here is my code, it’s in a server script inside the tool, with the animations in the script.
local leftPunch = script:WaitForChild("LeftPunch")
local rightPunch = script:WaitForChild("RightPunch")
local tool = script.Parent
local debounce = false
local waitTime = 0.4
script.Parent.Activated:Connect(function()
local Character = tool.Parent
local Humanoid = Character.Humanoid
local RightAnimTrack = Humanoid:LoadAnimation(rightPunch)
local LeftAnimTrack = Humanoid:LoadAnimation(leftPunch)
if debounce == false then
debounce = true
-----------------------
local rn = math.random(1,2)
if rn == 1 then
RightAnimTrack:Play()
elseif rn == 2 then
LeftAnimTrack:Play()
end
-----------------------
wait(waitTime)
debounce = false
end
end)
Try using LoadAnimation on the Animator instead of the humanoid. If that doesn’t work then try using Print() where the animations are ran to see if they’re working
local leftPunch = script:WaitForChild("LeftPunch")
local rightPunch = script:WaitForChild("RightPunch")
local tool = script.Parent
local debounce = false
local waitTime = 0.4
script.Parent.Activated:Connect(function()
local Character = tool.Parent
local Humanoid = Character.Humanoid
local RightAnimTrack = Humanoid:LoadAnimation(rightPunch)
local LeftAnimTrack = Humanoid:LoadAnimation(leftPunch)
if debounce == false then
debounce = true
-----------------------
local rn = math.random(1,2)
if rn == 1 then
print("Debug1")
RightAnimTrack:Play()
elseif rn == 2 then
print("Debug2")
LeftAnimTrack:Play()
end
-----------------------
wait(waitTime)
debounce = false
end
end)
Try loading the animations outside of the function. Maybe they aren’t getting loaded fast enough. Plus, you don’t need to do it everytime the tool is activated anyways, only at the beginning of the script.
local leftPunch = script:WaitForChild("LeftPunch")
local rightPunch = script:WaitForChild("RightPunch")
local tool = script.Parent
local debounce = false
local waitTime = 0.4
local Character = tool.Parent
local Humanoid = Character.Humanoid -- Error Line
local RightAnimTrack = Humanoid:LoadAnimation(rightPunch)
local LeftAnimTrack = Humanoid:LoadAnimation(leftPunch)
script.Parent.Activated:Connect(function()
if debounce == false then
debounce = true
-----------------------
local rn = math.random(1,2)
if rn == 1 then
print("Debug1")
RightAnimTrack:Play()
elseif rn == 2 then
print("Debug2")
LeftAnimTrack:Play()
end
-----------------------
wait(waitTime)
debounce = false
end
end)
maybe he should do a nested connection then? Equipped with Activated inside (He can use the :Once event for the inner connection to avoid any memory leak)
local activated = nil
local animation = nil
tool.Equipped:Connect(function()
-- Load animations in this block...
animation = humanoid:WaitForChild("Animator"):LoadAnimation(...)
activated = tool.Activated:Connect(function()
-- Play animations...
end)
end)
tool.Unequipped:Connect(function()
activated:Disconnect()
end)
@Shabo_Neeno@aiden9486 something like this?
I get this strange feeling there’s an easier way to do this but I just can’t pinpoint it lol. I’m a little rusty