I have been researching the devforums and every youtube tutorial for an hour and a half now and I haven’t gone any fix to this script:
Basically, whenever the Shift Key is pressed and state is running, a custom run animation will play but somehow it doesn’t work. Please help me (I ran out of braincells lol)
Edit: No errors show up, just to clear up some confusion
local UserInput = game:GetService("UserInputService")
local Camera = game.Workspace.Camera
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quint, Enum.EasingDirection.Out, 0, false, 0)
local ModifiedFieldOfView = 70
local CameraTweenSprinting = TweenService:Create(Camera, tweenInfo, {FieldOfView = 90})
local CameraTweenNormal = TweenService:Create(Camera, tweenInfo, {FieldOfView = 70})
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local remoteEvents = replicatedStorage.RemoteEvents
local Sprint = remoteEvents:WaitForChild("Sprint")
--local Anim = Instance.new("Animation", workspace)
local Animation = game.Workspace.Animation
local SprintPlay = Character:WaitForChild("Humanoid"):LoadAnimation(Animation)
UserInput.InputBegan:Connect(function(input, GDE)
if input.KeyCode == Enum.KeyCode.LeftShift then
Sprint:FireServer("Began")
Animation:Play()
if Camera then
CameraTweenSprinting:Play()
end
end
end)
UserInput.InputEnded:Connect(function(input, GDE)
if input.KeyCode == Enum.KeyCode.LeftShift then
Sprint:FireServer("Ended")
Animation:Stop()
if Camera then
CameraTweenNormal:Play()
end
end
end)
Camera should be workspace.CurrentCamera, instead of humanoid:LoadAnimation(), use animator:LoadAnimation(). animator is located inside of the humanoid.
Another problem is you aren’t waiting for RemoteEvents. If you’re using a script inside of a player you need to wait for pretty much everything to load before your script can work.
The Code is Called since the Camera is tweened as intended and the Remote Event is fired which modifies the WalkSpeed, and yes the animation is checked and is valid
Sadly It still doesn’t work yet, but I do have a question, what does Changing the name of the variables have to do with this, is there any sort of functionality in Roblox? Tell me more
This might not really help solving the issue, but its better to make the code better. Humaoid:LoadAnimation() is deprecated, rather. Use Humanoid.Animator:LoadAnimation().
I am bad at explaining so I’mma let roblox explain: This function loads an Animation onto a Humanoid , returning an AnimationTrack that can be used for playback.
The names of the variables don’t really have to do anything with this though.
You can put prints through out the script to see where it is working and where it is not if there is an error with the script. I know you said there are no errors in the output though.
Alr somehow it works now, my studio actually crashed then when I opened the team project it works, I havent made any changes but idk why it works now. Tnx for the help tho