Issues with SpeedCoil, Custom Animations, Sounds and WalkSpeed

It seems to have some issues again, it always keeps playing and doesn’t stop, even when the tool is unequiped or im not moving. I tried changing the animation creation lines to before the equipped event, so i could pause it when the tool was unequipped, but that doesn’t work and it continues to play even without the tool being equipped but that didn’t work.

local Tool = script.Parent
local Handle = Tool:WaitForChild('Handle')
local CoilSound = Handle:WaitForChild('CoilSound')
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChild('Humanoid')
local RunSpeed,SpeedConnection = 30,nil
local RunMain = Character:FindFirstChild("RunMain")
local playermainSound = Character:FindFirstChild("PLRSounds")

local Animator = Humanoid:FindFirstChild("Animator")

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://17450450382"
local animationTrack = Animator:LoadAnimation(animation)

Tool.Equipped:Connect(function()

	if Humanoid.MoveDirection.Magnitude > 0 then
		animationTrack:Play()
	else
		animationTrack:Stop()
	end

	CoilSound:Play()
	Humanoid.WalkSpeed = RunSpeed
	RunMain.Enabled = false
	playermainSound.Enabled = false
	Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("Running").SoundId = "rbxassetid://6523472922"
	Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("Running").PlaybackSpeed = 1
	if SpeedConnection == nil then
		SpeedConnection = Humanoid.Changed:Connect(function()
			if Humanoid.WalkSpeed ~= RunSpeed then
				Humanoid.WalkSpeed = RunSpeed
			end
		end)
	end
end)
Tool.Unequipped:Connect(function()
	if SpeedConnection ~= nil then
		SpeedConnection:Disconnect()
		SpeedConnection = nil
	end
	animationTrack:Stop()
	Humanoid.WalkSpeed = 14
	Character:WaitForChild("HumanoidRootPart"):FindFirstChild("Running").SoundId = "rbxassetid://9083849830"
	playermainSound.Enabled = true
	RunMain.Enabled = true
end)


1 Like

I did a re-check and it stops now, but i forgot to said some other details, it also replaces the Jump animation so it doesn’t play and again only keeps playing the main animation which was inserted in, it also only checks Once if the player is moving or not, so for example if i equipped the Coil while i was standing still it wouldn’t play the animation, since it was only checked for once if the player was moving, then doesn’t do anything after.

Yea I realized afterwards that you’re going to have to use a while loop or runservice to constantly check if the player is moving. I’m not sure about why the jump animation is being replaced, but try this and let me know what happens.

local Tool = script.Parent
local Handle = Tool:WaitForChild('Handle')
local CoilSound = Handle:WaitForChild('CoilSound')
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChild('Humanoid')
local RunSpeed,SpeedConnection = 30,nil
local RunMain = Character:FindFirstChild("RunMain")
local playermainSound = Character:FindFirstChild("PLRSounds")

local Animator = Humanoid:FindFirstChild("Animator")

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://17450450382"
local animationTrack = Animator:LoadAnimation(animation)

Tool.Equipped:Connect(function()
	CoilSound:Play()
	Humanoid.WalkSpeed = RunSpeed
	RunMain.Enabled = false
	playermainSound.Enabled = false
	Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("Running").SoundId = "rbxassetid://6523472922"
	Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("Running").PlaybackSpeed = 1
	if SpeedConnection == nil then
		SpeedConnection = Humanoid.Changed:Connect(function()
			if Humanoid.WalkSpeed ~= RunSpeed then
				Humanoid.WalkSpeed = RunSpeed
			end
		end)
	end
	game:GetService("RunService").Heartbeat:Connect(function()
		if Tool.Unequipped then return end
		if Humanoid.MoveDirection.Magnitude > 0 then
			animationTrack:Play()
		else
			animationTrack:Stop()
		end
	end)
	
	
end)
Tool.Unequipped:Connect(function()
	if SpeedConnection ~= nil then
		SpeedConnection:Disconnect()
		SpeedConnection = nil
	end
	animationTrack:Stop()
	Humanoid.WalkSpeed = 14
	Character:WaitForChild("HumanoidRootPart"):FindFirstChild("Running").SoundId = "rbxassetid://9083849830"
	playermainSound.Enabled = true
	RunMain.Enabled = true
end)

The Animation doesn’t seem to be playing now, but everything else in the script works

I don’t even know what’s wrong anymore. I tried adding a boolean value here. Maybe this will work.

local Tool = script.Parent
local Handle = Tool:WaitForChild('Handle')
local CoilSound = Handle:WaitForChild('CoilSound')
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChild('Humanoid')
local RunSpeed,SpeedConnection = 30,nil
local RunMain = Character:FindFirstChild("RunMain")
local playermainSound = Character:FindFirstChild("PLRSounds")
local toolEquipped = false

local Animator = Humanoid:FindFirstChild("Animator")

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://17450450382"
local animationTrack = Animator:LoadAnimation(animation)

Tool.Equipped:Connect(function()
	toolEquipped = true
	CoilSound:Play()
	Humanoid.WalkSpeed = RunSpeed
	RunMain.Enabled = false
	playermainSound.Enabled = false
	Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("Running").SoundId = "rbxassetid://6523472922"
	Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("Running").PlaybackSpeed = 1
	if SpeedConnection == nil then
		SpeedConnection = Humanoid.Changed:Connect(function()
			if Humanoid.WalkSpeed ~= RunSpeed then
				Humanoid.WalkSpeed = RunSpeed
			end
		end)
	end
	game:GetService("RunService").Heartbeat:Connect(function()
		if not toolEquipped then return end
		if Humanoid.MoveDirection.Magnitude > 0 then
			animationTrack:Play()
		else
			animationTrack:Stop()
		end
	end)
	
	
end)
Tool.Unequipped:Connect(function()
	toolEquipped = false
	if SpeedConnection ~= nil then
		SpeedConnection:Disconnect()
		SpeedConnection = nil
	end
	animationTrack:Stop()
	Humanoid.WalkSpeed = 14
	Character:WaitForChild("HumanoidRootPart"):FindFirstChild("Running").SoundId = "rbxassetid://9083849830"
	playermainSound.Enabled = true
	RunMain.Enabled = true
end)

Yeah now it just keeps looping over the start of the animation LOL i’m so sorry if this is bothering you a lot

Is everything else working fine? Does the animation stop playing if you stop moving? Does it stop when the tool is unequipped? If that’s all good then I’m sure it’s just a simple problem. My guess is that it’s something with the Runservice.Hearbeat and maybe you would need to use some other event with runservice idk. Just try a while loop and see how that works. Someone else might hop in here and spot the problem lol but I’m going to get off.

Yes everything else works fine, stops when i stop moving and unequipped it’s just the animation being looped over and not playing, i tried a while loop and it has the same result

Hello, I figured out the problem earlier if you still need help. I stopped the animation from replaying by adding an if statement to check if the animation wasn’t previously playing. If it was playing then the animation won’t play again. I solved the issue with the animation playing even when the player jumped by using the HumanoidStateType. I would suggest looking at the documentation.

local Tool = script.Parent
local Handle = Tool:WaitForChild('Handle')
local CoilSound = Handle:WaitForChild('CoilSound')
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChild('Humanoid')
local RunSpeed,SpeedConnection = 30,nil
local RunMain = Character:FindFirstChild("RunMain")
local playermainSound = Character:FindFirstChild("PLRSounds")
local toolEquipped = false
local isJumping = false

local Animator = Humanoid:FindFirstChild("Animator")

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://17450450382"
local animationTrack = Animator:LoadAnimation(animation)

Tool.Equipped:Connect(function()
	toolEquipped = true
	CoilSound:Play()
	Humanoid.WalkSpeed = RunSpeed
	RunMain.Enabled = false
	playermainSound.Enabled = false
	Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("Running").SoundId = "rbxassetid://6523472922"
	Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("Running").PlaybackSpeed = 1
	if SpeedConnection == nil then
		SpeedConnection = Humanoid.Changed:Connect(function()
			if Humanoid.WalkSpeed ~= RunSpeed then
				Humanoid.WalkSpeed = RunSpeed
			end
		end)
	end
	game:GetService("RunService").Heartbeat:Connect(function()
		if Humanoid.MoveDirection.Magnitude > 0 then --Check if character is moving
			if not animationTrack.IsPlaying then --If the animation track isn't playing then it'll start playing
				if Humanoid:GetState() == Enum.HumanoidStateType.Running then --Play the animation if running
					animationTrack:Play()
				else
					animationTrack:Stop()
				end
				Humanoid.StateChanged:Connect(function(oldState, newState)
					if newState == Enum.HumanoidStateType.Jumping then
						if not isJumping then --Stop the animation if jumping
							isJumping = true
							animationTrack:Stop()
						end
					elseif newState == Enum.HumanoidStateType.Landed then
						if isJumping then --Play the animation if landed
							isJumping = false
							animationTrack:Play()
						end
					end
				end)
			end

		else
			animationTrack:Stop()
		end
	end)
end)
Tool.Unequipped:Connect(function()
	toolEquipped = false
	if SpeedConnection ~= nil then
		SpeedConnection:Disconnect()
		SpeedConnection = nil
	end
	animationTrack:Stop()
	Humanoid.WalkSpeed = 14
	Character:WaitForChild("HumanoidRootPart"):FindFirstChild("Running").SoundId = "rbxassetid://9083849830"
	playermainSound.Enabled = true
	RunMain.Enabled = true
end)

I tested this out and I don’t see any bugs. If you want the animation to stop or play for certain actions for example when climbing you can add another elseif statement to stop/play the animation. Or if you want you can add your own separate animations for jumping, falling, climbing, etc.


I just don’t understand how the hell this happens if everything else in the script goes successfully But the part where it stops the animation, the output also says nothing.

Add if not toolEquipped then return end into the Runservice.Heartbeat Sorry, I had this in the other script I sent before but I guess I dropped it by mistake.

Sorry for the delay but yes, this works now!

1 Like

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