Play is not a valid member of Animation

I am learning how to use a module script with a combat system and it is working to the point of where it has to play an the hit animation at which point it gives an error/ Play is not a valid member of Animation, the module script also contains the function for the server side of the combat system but that works perfectly

I tried moving the location of the animation in multiple different places like the replicated storage, server storage and parenting it to the local script.
wait for child and find first child doesnt work.

inside the local script

local player = game:GetService("Players").LocalPlayer
local uis = game:GetService("UserInputService")
local simplePunch = require(game.ReplicatedStorage.combatLibrary)
local keybind = Enum.KeyCode.E

local animation = script:WaitForChild("simplePunch1")

uis.InputBegan:Connect(function(input, IS)
	if IS == true then return end

	if input.keyCode == keybind then
		simplePunch.combatSkillClient(3, animation) -- calling the combatSkill from library
	end
end)

inside the module script

function combat.combatSkillClient(cooldown, animation)
	local player = game.Players.LocalPlayer
	local debounce = false
	
	if debounce == true then return end
	debounce = true
	game.ReplicatedStorage.combatSkills.SimpleHit:FireServer() -- fires remove event to the server
	
	local anim = animation:Clone()
	anim:Play()
    game.Debris:AddItem(anim, 2)

	print("E was pressed")
	wait(cooldown)
	debounce = false
end

and this is the error
image

2 Likes

Animations need to be loaded into either a humanoid (i believe) or an animator. When they are loaded, it returns another object that then has the :Play function

1 Like

You need to first load the animation like so:

local Character = -- path to your character
local Animator = Character:FindFirstChild("Animator",true)
local Animation = -- path to animation
local LoadedAnimation = Animator:LoadAnimation(Animation)
LoadedAnimation:Play()
3 Likes

I added this inside of the module script and it worked, thanks

1 Like

Set his reply as a solution if it worked.

2 Likes

You should see a solution button next to the like button, please click it to let everyone know that this post has been solved and that my reply is the solution.

2 Likes

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