AnimationTracks to Animations using modules and scripts

how to get an animation instance by an animation track using Humanoid…GetPlayingAnimationTracks()?

script.Parent.Activated:Connect(function()
		
			WeaponModule.WeaponAttack(script.Parent,"GreatSword") --this is function of a moduleScript that receive these 2 parameters: the tool and the tool Category
		--the module plays an animation and thats what i need to get
			for i,v in pairs(Character.Humanoid:GetPlayingAnimationTracks()) do
				if v.Name == "Slash1" or v.Name == "Slash2" or v.Name == "Slash3" or v.Name == "Slash4" then --this is just a test i know is bad
						Animation = v
				end
			end
			Character.Humanoid.Animator:LoadAnimation(Animation):GetMarkerReachedSignal("attackStart"):Connect(function() -- where i get the error
			WeaponModule.StartAttack(script.Parent,"GreatSword")
			end)
	end)

tried this with the error LoadAnimation requires an Animation object

3 Likes

Have you tried debugging by printing Animation?

I see you set Animation = v but have you seen what v is?

Ill try to whip up solution by fixing up your code give me a moment

2 Likes

local Humanoid = Character.Hmanoid --// I'd just define all that outside easier reading/debuggng
script.Parent.Activated:Connect(function()

	WeaponModule.WeaponAttack(script.Parent,"GreatSword") --// Your Module script line
	
	local function CheckSlashes(v) --// your conditions just for readability rn 
		return v.Name == "Slash1" or v.Name == "Slash2" or v.Name == "Slash3" or v.Name == "Slash4" 
	end
	for i,v in pairs(Humanoid:GetPlayingAnimationTracks()) do
		--// If i knew what your index and values were i'd name it em
		
		print(i,v) --// We gottha see what were workin with
		
		if  CheckSlashes(v) then --// Your conditinal before wasnt bad I'm just extra (._.'
			print("Setting Animation to "..v)
			Animation = v --// Is Animation Defined outside of this Event?
			break --// Stops loop
		end
	end
	
	if not Animation then
		warn("We got no Animation")
		return --// Stops script / We got no Animation 
	else
		warn("We got the Animation",Animation)
	end
	
	local  AnimationTrack = Humanoid.Animator:LoadAnimation(Animation)
	
	AnimationTrack:GetMarkerReachedSignal("attackStart"):Connect(function() --//Error occurs u said 
		--// I wanna kno more about your animation marker
		WeaponModule.StartAttack(script.Parent,"GreatSword") ---// Starts Hit detection I assume (._.'
	end)
end)

Here is what I whipped together with some questions I’ll be developing for the next few hours, but I’ll try to pop in and help if you respond.

Edit: Also just noticed that you dont have a line that says AnimationTrack:Play() so idk how :GetMarkerReachedSignal() Would error :thinking: I’m curious if you did and where

In the case, I don’t get back to ya… Check your AnimationMarker name and make sure its on the Animation you are trying to play. I have a well-maintained script that uses animation and markers for weapons and character agility and modules, so I’m well-versed with this so am happy to help

1 Like

yeah i wanted to talk about it but it prints the (correct) animation name, but not the parent. anyway i “fixed” it by getting the playing animation by the module script, i wont make this as a solution yet

the thing is, the script doesnt make any error but still it doesnt work ( mine, i checked yours and tried to fix mine), so i think the problem is the module script, i will try to rewrite it entirely cause i made a mess

If you have any questions, i’m here for a while I could take a look at the module script If you like I literally strictly work with them these days

i just deleted the module, but i will ask you some questions if i encounter the same problem ( of course i will)

Why did you delete it? It could have been salvageable, but if that’s what you wanted, it’s fine.

Edit: You should brainstorm what you want it to do. then just list the function names. or tables and variables you will need. eventually thinking about what you really need and how to make things more efficient.

I was going to tell you how I’ve done my weapon modules but my systems are quite complex I even get confused sometimes with the way I loop server-client interaction within these modules

my bad

--as i said, the script is heavily modified
function WeaponModule.StartAttack(Tool, weaponType)
	
	local hitDebounce = {}

	local Character = Tool.Parent
	WeaponModule.slashPlaying = Character.Humanoid.Animator:LoadAnimation(anims:FindFirstChild(weaponType):FindFirstChild("Slash"..WeaponModule.combo))

	local slashSpeed = Tool:GetAttribute("SlashSpeed")
	local damage = Tool:GetAttribute("Damage")

	local hitbox = Tool:WaitForChild("Hitbox")
	
	print("Start")

	hitbox.CanTouch = true
	hitbox.Transparency = 1

	sounds.SwordSlash:Play()

	hitbox.Touched:Connect(function(hit)

		if not canHit and hit.Parent:FindFirstChild("zHumanoid") and hit.Parent.zHumanoid.Health ~= 0 and not table.find(hitDebounce,hit.Parent.zHumanoid) then

			table.insert(hitDebounce, hit.Parent.zHumanoid)

			if hit.Parent.zHumanoid then
				hit.Parent.zHumanoid:TakeDamage(damage)
			else
				hit.Parent.zHumanoid:TakeDamage(damage) --just to make sure
			end

			----------------------------

			sounds.SwordLunge:Play()

			local knockback = Instance.new("BodyVelocity")
			knockback.Parent = hit.Parent.HumanoidRootPart

			local hitParticle = replicatedStorage.Folder.Particles.HitParticle:Clone()
			hitParticle.Parent =  hit
			hitParticle.Enabled = true

			task.delay(.3, function()
				hitParticle.Enabled = false
				task.wait()
				hitParticle = nil
			end)

			knockback.MaxForce = Vector3.new(80000,80000,80000)
			knockback.Velocity = Character.HumanoidRootPart.CFrame.lookVector * 10

			task.delay(.5, function()
				knockback.Velocity = Vector3.zero
				--knockback = nil
			end)

			---------------------------
			task.delay(.3, function()
				table.remove(hitDebounce,1)
				print("Works?") --no
			end)
		end
	end)
end

for now the problem isnt this, as the output says Backpack.GreatSword.Script:19: attempt to index nil with ‘GetMarkerReachedSignal’, so the problem is from the script and not the Module ( for now )

WeaponModule.slashPlaying:GetMarkerReachedSignal("attackStart"):Connect(function()
1 Like

The line from the script. That’s erroring. Can I see it?

Edit: reading you script I see in your conditional for the Hitbox.Touched you have canHit, which is never defined. Theres a lot of clutter but your smart and headed in a good direction keep up the good work


local WeaponModule = require(workspace.Modules.WeaponModule)

local Tool = script.Parent

local Character
local slashSpeed = Tool:GetAttribute("SlashSpeed")
local damage = Tool:GetAttribute("Damage")
local Type = Tool:GetAttribute("weaponType")

local hitbox = Tool:WaitForChild("Hitbox")

script.Parent.Equipped:Connect(function()
	Character = Tool.Parent
	script.Parent.Activated:Connect(function()
		
	WeaponModule.WeaponAttack(script.Parent,"GreatSword")  --this works
	
	print("Check") -- checks
	
	WeaponModule.slashPlaying:GetMarkerReachedSignal("attackStart"):Connect(function() --this line breaks everything
		print("almost")
		WeaponModule.StartAttack(script.Parent,Type)
		print("done")
		end)
	end)
end)


1 Like

I DID ITTTT I DID ITTTTT

in the module i just set the SlashPlaying to nil, im very sorry to have wasted your time

1 Like

It’s alright. It was fun helping you.

Also, work on declaring variables for later usage. it will help you in the long run when you need to fix your code

1 Like

ah yeah, these variables are definied at the start of the code, i didnt put them cause are not “important” for this case but yeah

thats what im working on, and thats the main reason i broke the code haha, thank you

1 Like

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