Hey! I made an shift to sprint script where a camera zooms out and an runAnim starts playing! The only thing is that the RunAnim plays when jumpin too witch is really wierd. I know that the animation plays when hitting shift and that the anim will stop play when shift key is up but i can't come up with another idea on how to make the RunAnim work. Can somebody plz help me!!!
Heres The Script:
local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character
local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")
UIS.InputBegan:connect(function(input)--When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35.
local CurrentTime = tick()
if input.KeyCode == Enum.KeyCode.LeftShift then
if humanoid.MoveDirection.Magnitude > 0 then
local ts = game:GetService("TweenService")
local info = TweenInfo.new(
1, -- Time
Enum.EasingStyle.Back, -- EasingStyle
Enum.EasingDirection.InOut, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local tweenObject = ts:Create(game.Workspace.CurrentCamera,info,{FieldOfView = 120})
local normal = ts:Create(game.Workspace.CurrentCamera,info,{FieldOfView = 70})
tweenObject:Play()
Character.Humanoid.WalkSpeed = 25
local Anim = Instance.new('Animation')
Anim.AnimationId = 'rbxassetid://5984168294'
PlayAnim = Character.Humanoid:LoadAnimation(Anim)
PlayAnim:Play()
else
if humanoid.MoveDirection.Magnitude == 0 then
PlayAnim:Stop()
end
end
end
end)
UIS.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
local ts = game:GetService("TweenService")
local info = TweenInfo.new(
1, -- Time
Enum.EasingStyle.Back, -- EasingStyle
Enum.EasingDirection.InOut, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local tweenObject = ts:Create(game.Workspace.CurrentCamera,info,{FieldOfView = 120})
local normal = ts:Create(game.Workspace.CurrentCamera,info,{FieldOfView = 70})
normal:Play()
Character.Humanoid.WalkSpeed = 9
PlayAnim:Stop()
end
end)

1 comment
connect is deprecated. Use Connect. Humanoid:LoadAnimation() is also deprecated.