Issue with run Animation

hi im currently suck trying to make a run animation play specifically when the person receives any sort of boost to walk speed.

secondly: everytime I use a uis the first input never registers I have to press the key for the second time for it to work correctly after

local uis = game:GetService("UserInputService")
local runservice = game:GetService("RunService")
local rs = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").LocalPlayer
local chr = player.Character
local hum = chr:WaitForChild("Humanoid")
local ListOfWeapons = {
	"BasicSword",
	"RengokuSword",
	"PlaceHolder1",
}
local SpeedOn = false

uis.InputBegan:Connect(function(input,e)
	if e then return end
	if input.KeyCode == Enum.KeyCode.LeftControl then
		if SpeedOn then
			hum.WalkSpeed = 28
		end
		
		if not SpeedOn then
			hum.WalkSpeed = 16
		end
		
		SpeedOn = not SpeedOn
	end
end)

runservice.Heartbeat:Connect(function()
	for i,v in player.Character:GetChildren() do
		if table.find(ListOfWeapons, v.Name) and v:IsA("MeshPart") then
			if hum.WalkSpeed > 16 then
				local WeaponRunAnim = game:GetService("ReplicatedFirst").Animations.KatanaRun
				local loadRunAnim = hum:LoadAnimation(WeaponRunAnim)
				loadRunAnim:Play()
			else
				local WeaponWalkAnim = game:GetService("ReplicatedFirst").Animations.KatanaWalk
				local loadWalkAnim = hum:LoadAnimation(WeaponWalkAnim)
				loadWalkAnim:Play()

			end
		end
	end
end)

Try adding prints to part of the script to see where it’s being stopped.

1 Like

I think your issue here is that your debounce is triggering at the wrong time. At the moment, you have SpeedOn = not SpeedOn towards the end of your InputBegan logic. However, you’re relying on SpeedOn being changed to set the WalkSpeed earlier. I’d move that line to be after your if statement.

What I would do is to immediately call upon the animation and play it the moment you give the player boost. If there’s issues in how it looks, make sure your AnimationPriority is Action if you need it to override the default movement animation (without directly changing the defaults).

2 Likes

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