Errors with my punch script

A few days ago I tried to script the animations using the tutorial on the internet and the animation didn’t work. Today I tried from scratch to try to program a script for punching. I ran into a problem again where the animation doesn’t start and I get errors. I checked if I have everything in the right place and I looked at a few Developer Hub topics that mention the punching script, I checked their code and it seemed like I did everything right.

Here is my code and the errors I am getting and also where my script and animation is located.

  • location
  • code
local player = game.Players.LocalPlayer
local character = player.Character

local UIS = game:GetService("UserInputService")
local mouse = player:GetMouse()

local animation = script.Animation

	local humanoid = character:WaitForChild("Humanoid")
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		local animationTrack = humanoid:WaitForChild("Animator"):LoadAnimation(animation)
  • error

Animation is not a valid member of LocalScript “Workspace.dodo64bit.LocalScript”

1 Like

Never mind, I fixed it. It seems that the animation, even if it is already a child of the script, I still have to put the :WaitForChild() function.

But I’m still curious, why the :WaitForChild() function, why not just animation = script.Animation?

1 Like

WaitForChild() basically yields your script (stops it) until the child your are waiting for is done loading.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.