-
What do you want to achieve? Keep it simple and clear!
I want to make a walking animation and a running animation at different states of an enemy ( Such as it walks normally but when it sees you it runs )
-
What is the issue? Include screenshots / videos if possible!
I’m using humanoid.Running functions to detect when to play the animations and I’m trying to use the :Disconnect function to disconnect the walking function and temporarily replace it with the running function, and vice versa but it doesn’t break the connection.
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have looked everywhere, Dev Forum, Google, Youtube, I even tried using Disconnect on a new baseplate and it worked however it doesn’t on my game. Nothing seemed to help.
This is my code:
while task.wait(0.5) do
Connection = humanoid.Running:Connect(function()
if walkTrack.IsPlaying == false then
warn("Walking")
walkTrack:Play()
Connection:Disconnect() -- This one seems to disconnect properly
end
end)
---------- This section is irrelevent but if you need to see it just ask.
---------- It's just some raycasting stuff
if hit.Parent:FindFirstChild("Humanoid") then -- detects player with ray
if walkTrack.IsPlaying == true then
walkTrack:Stop() -- stops monster from using the walking animations
end
humanoid.PlatformStand = true
task.wait(4)
humanoid.PlatformStand = false
script.Parent.Humanoid.WalkSpeed = 25
roar:Play()
while task.wait(1) do
Connection2 = humanoid.Running:Connect(function()
warn("Run Checker Ran")
-- this is the problem function
-- It checks if the monster humanoid is running then plays an animation
if runTrack.IsPlaying == false then
print("Running")
runTrack:Play()
Connection2:Disconnect()
--it disconnects but the function still repeats for about 1000 times
end
end)
if (torso.Position - script.Parent.PrimaryPart.Position).Magnitude >= 200 or not
-- this checks if the monster killed the player, so the monster should stop running
hit.Parent:FindFirstChild("Humanoid") then
warn("Player gone or dead")
script.Parent.Humanoid.WalkSpeed = 10
runTrack:Stop()
roar:Stop()
break
end
-- then the while loop at the top repeats because if the running function
-- disconnects that means the monster killed the player and reset
end
end
end
end
end
end
This has been extremely frustrating, thanks to anyone who responds in advance!