What do you want to achieve? I want the animation to start when the player moves while holding shift.
What is the issue? The issue is that when you hold the shift, the animation just starts.
What solutions have you tried so far? I tried looking for answers in the DevForum, but I couldn´t find anything.
Here is a video:
and here is the script:
local char = plr.Character
local humanoid = char:FindFirstChild("Humanoid")
local hrp = char:FindFirstChild("HumanoidRootPart")
local UIS = game:GetService("UserInputService")
local RA = Instance.new("Animation")
RA.AnimationId = "rbxassetid://12733397822"
local playRA = humanoid:LoadAnimation(RA)
UIS.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftShift then
humanoid.WalkSpeed = 24
playRA:Play()
end
end)
UIS.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftShift then
humanoid.WalkSpeed = 16
playRA:Stop()
end
end)
-- top of script
local isRunning = false
local minRunningSpeed = 0 -- change this if you want
UIS.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftShift then
humanoid.WalkSpeed = 24
isRunning = true
end
end)
UIS.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftShift then
humanoid.WalkSpeed = 16
isRunning = false
end
end)
local function onRunning(speed)
if speed > minRunningSpeed and isRunning then
playRA:Play()
else
playRA:Stop()
end
end
humanoid.Running:Connect(onRunning)
if key.KeyCode == Enum.KeyCode.LeftShift and Enum.KeyCode.W then
(So they have to be walking for the animation to play)
or try something like this v
humanoid.Running:Connect(function(speed)
if speed > 0 then
UIS.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftShift then
humanoid.WalkSpeed = 24
playRA:Play()
end
end)
end
end)
This has the problem of listening to an input multiple times, since you are not using :Disconnect() on the event, also, you cannot press shift before walking, and lastly this uses a lot of nesting, which is not a preferred practice.
So, thai mean taht if the player is pressing leftShift, but is not moving, it will not make the Player run and stop the animation, if he’s pressing LeftShift and he’s moving he will run, and play the animation, clear now?