Animation Script Issue

No idea how to explain it but i will try
so in my game my npc must die when 2 conditions are met (dont worry i know how to do this)
the issue is getting the second condition, because in order to kill it you have to be touchign it and also have the animation playing but the npc will die even if you just walk over it so im not getting the second condition .
the animation is on another script which is why i have problems with it.
here is the script with the function im trying to get work

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local Character = script.Parent
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local foot = Character:WaitForChild("Right Foot")
local Bob = game.Workspace:WaitForChild("Bob")

local Animator = Humanoid:FindFirstChildOfClass("Animator")
local AnimationTracks = Animator:GetPlayingAnimationTracks("SlideTrack")
local SlideAnim = game.StarterPlayer.StarterCharacter["YaYa Animations"]["YaYA  SLIDE"]



function slideDmg(hit)
	Bob= hit.Parent
	if AnimationTracks then
		print("playing")
		if hit.Parent:FindFirstChild("Humanoid") and AnimationTracks then
			print("cond met")
			game.ReplicatedStorage.DamageEvent:FireServer(Bob)
			task.wait()
		else
			print("not met")
		end
	end
end


foot.Touched:Connect(slideDmg)

and here is the function in the other script to do with the animation

local function Slide(input, _gameProcessed)
	if _gameProcessed then return end
	if input.KeyCode == Enum.KeyCode.LeftShift then
		if Humanoid.MoveDirection.Magnitude > 0 then
			if debounce then
				return
			end
			debounce = true
			Humanoid.JumpPower = 0
			WalkTrack:Stop()
			task.wait(0.1)
			SlideTrack:Play()
			task.wait(1)
			SlideTrack:Stop()
			Humanoid.JumpPower = 50
			debounce = false

		end

	end
end
UserInputService.InputBegan:Connect(Slide)

pls help me confused

1 Like

it seems like the track only plays when the npc spawns and doesnt stop playing even though it isnt playing

What exactly are you trying to achieve? Also most of your scripts look wrong or odd, did anything print for the topmost script when played?

1 Like

its in the post dude and yes something is wrong thats why im asking for help, not everything is wrong you are just looking at spaghetti

this is the part thats wrong

if hit.Parent:FindFirstChild("Humanoid") and AnimationTracks then

Most of your code is wrong but the part that’s making it not work is the animation tracks part. you aren’t searching for the track correctly.

This is how:

For i, v in humanoid:GetPlayingAnimationTracks() do
if v == “SlideTrack” or v.Name == “SlideTrack” then AnimationTracks = v
end
end

Correct grammar errors, im on phone.

most likely but it works for now, some things are getting changed later on

i’ll give this a go

played around with it a little and its still the same issue so my it has to be

it is supposed to print when the track plays yet it prints as soon as the npc spawns

This is because you hooked up the function to a touched event… the npc touches to ground with their feet when they spawn. Give me a few moments to get on pc and I’ll rewrite your script, ma’am.

the event is for when the player touched the npc though

Does it print out “cond met” when it fires, ma’am?

yea it prints cond met when i just walk over when i changed animationtrack in the line to v, when its still animationtrack it prints not met

imma put this here…
vid 1 shows when i replace animationtracks with v in line
robloxapp-20240130-2042489.wmv (1.2 MB)

vis 2 here is when i dont replace it (the issue at hand)
robloxapp-20240130-2044052.wmv (583.5 KB)

ok so somehow the game still thinks the animation is playing. i noticed this because of the effect that plays when sliding. After the slide is finished the effect will keep playing, looping over faster and faster

thats cuz you only check for AnimationTracks at the top of the code, when the NPC is loaded in… try setting it inside of the slideDmg function.

And also you are using GetPlayingAnimationTracks *completely* wrong, use

2 Likes

no idea if im doing this right, i need a better explanation than what i get from the docs because i’ll be honest i get confused more and more.

i did what you said but i dont know if i did it correctly

function slideDmg(hit)
	Bob= hit.Parent

	local AnimationTracks = Humanoid:GetPlayingAnimationTracks("SlideTrack")

	for i, v in Humanoid:GetPlayingAnimationTracks() do
		if v == "SlideTrack" or v.Name == "SlideTrack" then 
			AnimationTracks = v
		end
		
		if hit.Parent:FindFirstChild("Humanoid") and AnimationTracks then
			print("cond met")
			game.ReplicatedStorage.DamageEvent:FireServer(Bob)
			task.wait()
		else
			print("not met")
		end
	end
end

same issue though

this script is for the player not the npc my dude

the scripts are local scripts in StarterCharacterScripts
the slide function is in the animate script with the rest of the animations
the script with the slideDmg function was made for adding damage through remote events
it seemed more appropriate to do it that way but maybe i should just merge the two scripts?

function slideDmg(hit)
	Bob= hit.Parent

	local AnimationTracks = Humanoid:GetPlayingAnimationTracks()
	local isPlaying = false

	for i, v in Humanoid:GetPlayingAnimationTracks() do
		if v == "SlideTrack" or v.Name == "SlideTrack" then 
			isPlaying = true
		end
	end

        if hit.Parent:FindFirstChild("Humanoid") and isPlaying then
		print("cond met")
		game.ReplicatedStorage.DamageEvent:FireServer(Bob)
		task.wait()
	else
		print("not met")
	end
end

should work

prints not met and doesnt kill the npc now