Not a valid member even though there is a valid member

Hello, I have been experiencing a roblox studio issue that I came across making my roblox game. This is the script: local alotofpunches = script.rapidpunchanim And I get the error rapidpunchanim is not a valid member of LocalScript “Workspace.ozifawaz3050.Attacks” Even though it the animation is in the script. Can someone help me with this?

2 Likes

Could you send the script setting the rapidpunchanim up and also the fully unfolded hierachy ingame?

1 Like

Sure here it is `local alotofpunches = script.rapidpunchanim
local humanoid = script.Parent.Humanoid
local alotofpunchesloaded = humanoid:LoadAnimation(alotofpunches)
local input = game:GetService(“UserInputService”)
local debounce = false

input.InputBegan:Connect(function()
if input.KeyCode == Enum.KeyCode.G then
if debounce == false then
humanoid.WalkSpeed = 0
alotofpunchesloaded:Play()
wait(3)
humanoid.WalkSpeed = 16
alotofpunchesloaded:Stop()
debounce = true
wait(5)
debounce = false
end
end
if input.KeyCode == Enum.KeyCode.F then
if debounce == false then
print(“Punches”)
debounce = true
wait(1)
debounce = false
end
end
end)`

Don’t show me the hierachy of StarterCharacterScripts but of the character when you playtest the game please.

Here
image

A minor issue was that you didn’t use the UserInputService correctly. You need the input parameter when firing the function but I fixed that for you.

Mainly, you are currently trying to use a deprecated method to load animations.
Humanoid:LoadAnimation() and AnimationController:LoadAnimation() were deprecated about 3 years ago. Overall Roblox is trying to remove Animation controllers as they have to be kept for “historical reasons” as official staff say.

The modern method to load an animation is using an Animator which is automatically included in a characters Humanoid.

Your code should look like this:

local UserInputService = game:GetService("UserInputService")

local char = script.Parent
local hum = char:FindFirstChild("Humanoid")
repeat wait() until hum
local animator = hum:FindFirstChild("Animator")
repeat wait() until animator

local alotofpunches = script.rapidpunchanim
local alotofpunchesloaded = animator:LoadAnimation(alotofpunches)
local debounce = false

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.G then
		if debounce == false then
			hum.WalkSpeed = 0
			alotofpunchesloaded:Play()
			wait(3)
			hum.WalkSpeed = 16
			alotofpunchesloaded:Stop()
			debounce = true
			wait(5)
			debounce = false
		end
	end
	if input.KeyCode == Enum.KeyCode.F then
		if debounce == false then
			print("Punches")
			debounce = true
			wait(1)
			debounce = false
		end
	end
end)

Announcement about deprecation of some LoadAnimation methods:

LoadAnimation documentation of Roblox:

It worked. I don’t really understand how it works but I can look deep into it but thanks for your help!

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