Why is my animation and sound script not working?

Hello! Im trying to make a animation and sound script in my game so I can have custom animations and custom sounds for my custom character.

Im getting no errors and my script is not working! How can I fix this?

My Script is located in StarterCharacterScripts

Script

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

local idleAnim = Instance.new("Animation")
idleAnim.AnimationId = "rbxassetid://7208722455"
local idleAnimTrack = humanoid.Animator:LoadAnimation(idleAnim)

local runAnim = Instance.new("Animation")
runAnim.AnimationId = "rbxassetid://7208894477"
local runAnimTrack = humanoid.Animator:LoadAnimation(runAnim)

local JumpSound = Instance.new("Sound")
JumpSound.SoundId = "rbxassetid://8396408200"
JumpSound.Parent = humanoid.Parent:WaitForChild("Torso")
JumpSound.Volume = 10

humanoid.Running:Connect(function(speed)
	if speed == 0 then
		idleAnimTrack:Play()
	else
		if speed > 0 then
			runAnimTrack:Play()
		else
			runAnimTrack:Stop()
		end
	end
end)

if humanoid.Jump == true then
	JumpSound:Play()
end

It seems that jump-sound has only been set to play, at the startup of your script and does not have a connection to the humanoid, unlike how your running does.

  • Other than that, I can not see anything that regards a script error [That is script related].

EDIT: Also, I advise running idle at startup instead, If the animation was set up accordingly then unless you use the stop function it will always run in the background. [That is if the animation is set to loop]

if you saw in the script though, it clearly says if humanoid.Jump, thats my gateway right their.

But It runs once… I am not exactly sure what you mean by “gateway”.

1 Like

here is a simplified way, thats my connection right their.

I do agree with you though, I should have added while true loops!

That would be my simple solution.

I marked this as my own solution specifically due to the fact that I found the answer.

humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
	if humanoid.Jump == true then
		JumpSound:Play()
	end
end)
  • A more correct term.