Hello I am Mario, I am trying to make a shift-to-sprint script and so far, with the fov tweening and the speed, its all working fine apart from the animation.
local tweenService = game:GetService("TweenService")
local hum = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local animation = hum:LoadAnimation(script.RunAnimation)
local info = TweenInfo.new(0.5)
local properties1 = {
FieldOfView = 80,
}
local properties2 = {
FieldOfView = 70,
}
local object = workspace.CurrentCamera
local IsRunning = script.IsRunning
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
IsRunning.Value = true
hum.WalkSpeed = 30
local camTween = tweenService:Create(object, info, properties1)
camTween:Play()
end
end)
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
IsRunning.Value = false
hum.WalkSpeed = 16
local camTween = tweenService:Create(object, info, properties2)
camTween:Play()
end
end)
hum.StateChanged:Connect(function(old,new)
if IsRunning.Value == true then
print("Running")
if new == Enum.HumanoidStateType.Running then
animation:Play()
print("Definitely")
else
animation:Stop()
end
else
animation:Stop()
end
end)
This is the script I made, but the animation doesnt play. The checks that I put in, the print("Running") and print("Definitely") both print. Infact it only prints and plays the animation when im close to a particular dummy in workspace, yet I didnt code it to do that.
Hi there TheUnRealMario, a couple things regarding the animation. First off, ensure that:
The Animation is yours
The Animation’s Priority is set properly.
I know many Roblox tutorials inform you to use that method for loading in animations. I found a more reliable way to load animations. Here’s the code for it:
local character = script.Parent
local humanoid = character:WaitForChild(“Humanoid”)
local animator = humanoid:FindFirstChild(“Animator”)
local animation = Instance.new(“Animation”)
animation.AnimationId = “rbxassetid://IDHERE”
local animationTrack = animator:LoadAnimation(animation)
–This is a localscript located within StarterCharacterScripts
In terms of it only running when you’re near a dummy… it might just be coincidence. I hope this helps! Keep me updated!
I’ve seen someone post a problem similar to yours and I believe they solved the issue be reanimating or reexporting the animation. Unfortunately I can’t find that post at the moment. In addition to that, I would load the animation not to the humanoid, but to the Animator, which I believe can be found as a child instance of humanoid.
You can also set it in the script, but I honestly don’t remember what the property name is.
Probably:
animation.Priority = Enum.AnimationPriority.Action
Not to sure though
Animation weight
else
Animation Save as action
else
U can use movement detection with left shift checking
Hum:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if uis:IsKeyDown(Enum.KeyCode.LeftShift) then
if Hum.MoveDirection.X ~= 0 or Hum.MoveDirection ~= 0 then
if Anim.IsPlaying == false then
Anim:Play()
end
else
Anim:Stop()
end
else
if Anim.IsPlaying == true then
Anim:Stop()
end
end
end)