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)
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.
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
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
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