Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I have an animation be able to play if left shift is held down and the character is running?

I have an animation in which I want it to play when the player holds down left shift and ONLY when they are running. If they are holding it down and they jump, fall, or have any other movement different from running then the animation will end and it will play the animations I have for falling, jumping, and so on. I did make it so if left shift is held down the animation plays, but I can't get it so that the animation can only play when the player is running. Right now I have code put it for it to work when the player falls, and I tried it, but it didn't work. Here is my code.

local character = script.Parent

boostanim = character.Humanoid:LoadAnimation(character.BoostAnimation)

local humanoid = character:WaitForChild("Humanoid")

speed = character.Humanoid.WalkSpeed

game:GetService("UserInputService").InputBegan:connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then if speed > 0 then boostanim:Play() humanoid.FallingDown:Connect(function(isActive) -- I tried to make it work with falling input.KeyCode = input.KeyCode.BackSpace end)

end

end

end)

game:GetService("UserInputService").InputEnded:connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then boostanim:Stop() end end)

1 answer

I haven't really tested it but if I'm correct then this should be what you're looking for


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

local boostanim = humanoid:LoadAnimation(character.BoostAnimation)

game:GetService("UserInputService").InputBegan:Connect(function(input) 
	
	if input.KeyCode == Enum.KeyCode.LeftShift then 
		
		local fall = character.HumanoidRootPart.Velocity.Y
		local speed = character.Humanoid.WalkSpeed
		
		if speed > 16 and fall == 0 then 
			boostanim:Play()
		end
		
	end
end)

game:GetService("UserInputService").InputEnded:Connect(function(input) 
	if input.KeyCode == Enum.KeyCode.LeftShift then
		boostanim:Stop()
	end
end)

2 comments

0

It didn't work. It looks like it should've though. I got rid of the old script to test this one so they didn't interfere with each other and this script didn't work. I also realized when testing that the velocity doesn't change when falling or jumping.

0

Are you sure it didn't change when jumping or falling? Did the other values change? Try having a script print it or use Server side view instead of client.

This discussion is preserved as it was. New answers, comments, and votes are closed.