#If player is holding the sprintkey before moving, the animation nor movespeed will change

94 messages · Page 1 of 1 (latest)

icy raptor
#
-- Player starts sprinting when pressing LeftControl
UserInputService.InputBegan:Connect(function(input)
    if input.KeyCode == Sprint_Key then
        
        if humanoid.MoveDirection.Magnitude > 0 then -- Detects if the player is moving
            
            humanoid.WalkSpeed = Sprint_Speed
            animtrack:Play()
            
        end    
        
    end
end)
#

If the player is idle presses the sprint key then starts moving. The animation nor movespeed will change. I've got it like this so the animation doesnt play before moving, but need it too start playing when they do start moving

half crypt
#

You can put in an a game.RunService.RenderStepped

#

So it checks every frame

#

Because currently it only checks when the player starts an input

icy raptor
half crypt
#

Youch

#

Welp

#

I'll try type out a while scriot ig 🥱

#

Am on mobile

#

Lemme try either way

icy raptor
#

i think i understand what i need too do

#

RunService.RenderStepped:Connect

#

then connect it too userinput service

#

oh no

#

i connect it too movedirection

#

nope that wasnt it

#

definitelly not

half crypt
#
game.RunService.RenderStepped:Connect(function()
     if game.UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) and game.Players.LocalPlayer
Character.Humanoid.MoveDirection.Magnitude > 0 then
     humanoid.WalkSpeed = Sprint_Speed
     animTrack:Play()
end
end)
#

Sorry I'm on mobile

#

Idk if any errors

icy raptor
#

if game.UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) and game.Players.LocalPlayer
Why that

#

if input.KeyCode == Sprint_Key then

#

instead of just that

half crypt
#

Is

#

Passed as an arg from .InputBegan

#

So we would js chedk if shift is down

#

You could change it to

#

if game.UserInputService:IsKeyDown(Sprint_Key)

#

That also works

icy raptor
#

RunService is not a valid member of DataModel "Wilted Lands @ 08 Aug 2024 21:22"

half crypt
#

Send me ur whole script rn

icy raptor
#
local UserInputService = game:GetService("UserInputService")

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

local RunService = game:GetService("RunService")

-- Animation
local animation = script:WaitForChild("Animation")
local animtrack = humanoid:LoadAnimation(animation)

--        Settings        --

local Sprint_Key = Enum.KeyCode.LeftShift -- Input Key for Sprinting
local Sprint_Speed = 32
local Walk_Speed = 16

--        Main Code        --

print(humanoid:GetState())

-- Player starts sprinting when pressing LeftControl
game.RunService.RenderStepped:Connect(function()
    if game.UserInputService:IsKeyDown(Sprint_Key) and game.Players.LocalPlayer then
        
        if humanoid.MoveDirection.Magnitude > 0 then -- Detects if the player is moving
            
            humanoid.WalkSpeed = Sprint_Speed
            animtrack:Play()
            
        end    
        
    end
end)

-- Player stops sprinting when releasing LeftControl
UserInputService.InputEnded:Connect(function()
    
    humanoid.WalkSpeed = Walk_Speed
    animtrack:Stop()
    
end)
half crypt
#

Try RunService.RenderStepped

icy raptor
#

where

half crypt
#

Cuz you alr have a run service variable

icy raptor
#

ye the variable i added

half crypt
#

Change from game.RunService.RenderStepped to RunService.RenderStepped

icy raptor
#

weird ahh gltich

half crypt
#

Aight lemme fix one sec

#

animTrack.IsPlaying == false then animTrack:Play() end

#

Change to that

#

And then you will prob notice that when you stop holding it you still have the running speed and animation doesn't stop

icy raptor
half crypt
#

Put an if before that

icy raptor
#

Workspace.wandkeeper.Sprint_Script:30: Incomplete statement: expected assignment or a function call

half crypt
#

Btw is the original script AI?

icy raptor
#

no

#

I spent like 2 hours coding it

#

not 2

#

like 1

half crypt
#

Oh wow

icy raptor
#

why

half crypt
#

Thats long lol

icy raptor
#

I dont code

#

atall

half crypt
#

Btw it should be

#

How u have s1?

#

Nvm

#

Its modeler

icy raptor
#

cuz i dont

#

ye

half crypt
#

For someone who doesn't code 1 hour is actually fast

icy raptor
#

"doesnt code" i supposidly spent 3 years learning python

#

know nothing about it tho

half crypt
#

XD

icy raptor
#

cuz cs education in UK is useless

half crypt
#

Rip

#

Btw I'm pretty sure that in your script if you hold shift and don't move does it make you still play the anim?

icy raptor
#

no

#

not anymore

half crypt
#

and humanoid.MoveDirection.Magnitude > 0

#

Ohhh

icy raptor
#

im checking the move direction

half crypt
#

Didn't see

#

Okay nice

#

I think we could have solved this easier but

icy raptor
#

thats where most of the hour went

half crypt
icy raptor
#

since i spent most of it trying to do humanoid state

#

to stop the animation

#

then tried move direction and it worked instantly

half crypt
#

Yeah

#

Alr

#

Imma go now

icy raptor
#

cya

#

thx for the help

half crypt
#

Good Luck 👍