You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
Simple, I just want a partly advanced running script with animations. I also want to learn how to improve the code, if I can
What is the issue? Include screenshots / videos if possible!
The issue is with the detection of the player jumping, and also the detection if the player has stopped moving, which is used inside a function called Moved1()
Basically what the function does, is it checks if the player has stopped moving using a vector3 value, if the players move Direction equals to them, stop the running animations, its pretty simple.
1.) Anyway, the issues are, that whenever the player stops running, and starts to move again, the animation has stopped, and the speed has gone back to normal, but the player is still holding down the shift button.
2.) Whenever the player jumps, the animation stops, changed the players speed back to normal, but once they touch the ground again, the animation continued to play, and the speed is still at normal.
3.) If the player has pressed another button while running, the animation will still play, but the speed would go back to the normal walking speed.
4.) When the player moves their camera, their speed goes back to the default speed, and the animation continued to play
Video of bugs.)
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried to fix the code by editing the function, changing the speed, and trying to make another function too, the only thing that partly worked (I think) Are the changes of the Humanoid Walkspeed, which changes it back to normal, after the input began has ran through every line of code. (Check code below to view where the placements are)
Whenever i try to make another function, it doesn’t work, and just make a bunch of red lines instead.
This is the code that I am using. For this script, I’m using it inside of StarterCharacterScripts, and setting it as a local script.
--SETTINGS-- local DefaultSpeed = 16 local SprintSpeed = 28 local SprintKey = Enum.KeyCode.LeftShift local UIS = game:GetService("UserInputService") local PLayers = game:GetService("Players") local player = PLayers.LocalPlayer local Character = player.Character or player.CharacterAdded:Wait() local Humanoid = Character:WaitForChild("Humanoid") local RunAnimation = Instance.new("Animation") RunAnimation.AnimationId = "rbxassetid://9584328745" local PlayRunAnim = Humanoid:LoadAnimation(RunAnimation) local Running = false local VectorZero = Vector3.new(0, 0, 0) local function Moved1() if Humanoid.MoveDirection ~= VectorZero then else print("Stopped Moving") PlayRunAnim:Stop() Humanoid.WalkSpeed = SprintSpeed return end end Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(Moved1) Humanoid.WalkSpeed = DefaultSpeed UIS.InputBegan:Connect(function(key, gameProcessed) if key.KeyCode == SprintKey and gameProcessed == false then if not Running then Running = true if Humanoid.MoveDirection.Magnitude > 0 then if not PlayRunAnim.IsPlaying then Humanoid.WalkSpeed = SprintSpeed PlayRunAnim:Play(0.1) end end else Running = false Moved1() end return Moved1() end Humanoid.WalkSpeed = DefaultSpeed end) UIS.InputEnded:Connect(function(key) if key.KeyCode == SprintKey then Running = false if PlayRunAnim.IsPlaying then Humanoid.WalkSpeed = DefaultSpeed PlayRunAnim:Stop(0.1) end end end) Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function() if Humanoid.FloorMaterial == Enum.Material.Air then if Running then repeat wait() if PlayRunAnim.IsPlaying then PlayRunAnim:Stop(0.1) end until Humanoid.FloorMaterial ~= Enum.Material.Air if Running then if Humanoid.MoveDirection.Magnitude > 0 then if not PlayRunAnim.IsPlaying then PlayRunAnim:Play(0.1) end end else Running = false if PlayRunAnim.IsPlaying then PlayRunAnim:Stop(0.1) Humanoid.WalkSpeed = DefaultSpeed end end else if Running then if Humanoid.MoveDirection.Magnitude > 0 then if not PlayRunAnim.IsPlaying then Humanoid.WalkSpeed = SprintSpeed PlayRunAnim:Play(0.1) end end end end end end)
I have no Idea what else I could add to fix the issues, but if there are none, then thats fine.
Also, whenever I run the code, no errors pop up either (This could be useful or not, idk.)
So, is there any way for me to be able to fix these problems, or can I not do anything at all?