Hello, I currently need help on how to stop an animation if you are jumping.
I need help cause I have a deadline, so if you can tell me how, or just send me the script on how to fix this.
I currently cannot provide a video for this right now, but I can give you guys the script.
Script:
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char.Humanoid or char:WaitForChild("Humanoid")
local animTrack = script:WaitForChild("runningAnim")
local loadAnimTrack = hum:LoadAnimation(animTrack)
local default = 6
local sprinting = 15
local onSprinting = false
local onSprint = false
local jumping = false
local UIS = game:GetService("UserInputService")
hum.StateChanged:Connect(function(old, new)
if new == Enum.HumanoidStateType.Jumping or new == Enum.HumanoidStateType.Freefall then
jumping = true
while jumping == true do
wait()
onSprint = false
end
end
if new == Enum.HumanoidStateType.Landed then
jumping = false
while jumping == false and onSprinting == true do
wait()
onSprint = true
end
end
if new == Enum.HumanoidStateType.Landed then
jumping = false
while jumping == false and not onSprinting do
wait()
onSprint = false
end
end
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
while true do wait(0.1)
if hum.WalkSpeed > 6 then
onSprinting = true
onSprint = true
end
if hum.WalkSpeed <= 6 then
onSprinting = false
onSprint = false
end
end
if hum:GetState() == Enum.HumanoidStateType.Running or hum:GetState() == Enum.HumanoidStateType.RunningNoPhysics then
if hum.WalkSpeed > 6 and onSprint == true then
loadAnimTrack:Play()
elseif hum.WalkSpeed <= 6 and onSprint == false then
loadAnimTrack:Stop()
end
end
end
end)
end)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
hum.WalkSpeed = sprinting
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
hum.WalkSpeed = default
end
end)
I’ll respond to replies tomorrow since I’m going to sleep but,
thanks for helping!
Best way is editing the default roblox animation script, other than that you’re gonna have to deal with situational thinking to create your own state system.
I have currently tried that in the script but it causes a lot of bugs.
hum.StateChanged:Connect(function(old, new)
if new == Enum.HumanoidStateType.Jumping or new == Enum.HumanoidStateType.Freefall then
jumping = true
while jumping == true do
wait()
onSprint = false
end
end
if new == Enum.HumanoidStateType.Landed then
jumping = false
while jumping == false and onSprinting == true do
wait()
onSprint = true
end
end
if new == Enum.HumanoidStateType.Landed then
jumping = false
while jumping == false and not onSprinting do
wait()
onSprint = false
end
end
Nevermind I fixed it lol, I just switched some things up and it got fixed.
Script:
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char.Humanoid or char:WaitForChild("Humanoid")
local cam = workspace.CurrentCamera
local animTrack = script:WaitForChild("runningAnim")
local loadAnimTrack = hum:LoadAnimation(animTrack)
local default = 6
local sprinting = 15
local onSprinting, onSprint, jumping, onFOV = false, false, false, false
local UIS = game:GetService("UserInputService")
local ts = game:GetService("TweenService")
local FOVIn = ts:Create(cam, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {FieldOfView = cam.FieldOfView + 5})
local FOVOut = ts:Create(cam, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {FieldOfView = cam.FieldOfView - 5})
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
hum.WalkSpeed = sprinting
onSprinting = true
onFOV = true
loadAnimTrack:Play()
if onFOV == true then
FOVIn:Play()
end
hum.StateChanged:Connect(function(old, new)
if new == Enum.HumanoidStateType.Jumping or new == Enum.HumanoidStateType.Freefall then
jumping = true
if jumping == true then
wait()
onSprint = false
loadAnimTrack:Stop()
end
end
if new == Enum.HumanoidStateType.Landed then
jumping = false
if jumping == false and onSprinting == true then
wait()
onSprint = true
loadAnimTrack:Play()
end
end
if new == Enum.HumanoidStateType.Landed then
jumping = false
if jumping == false and not onSprinting then
wait()
onSprint = false
loadAnimTrack:Stop()
end
end
end)
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
hum.WalkSpeed = default
onSprinting = false
onFOV = false
loadAnimTrack:Stop()
if onFOV == false then
FOVOut:Play()
end
end
end)
I know I was late but I have a question, I tried the script and the animation was playing while idle, is there any way to fix this? Im a beginner so I dont really know how to do it.