-- 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 player is holding the sprintkey before moving, the animation nor movespeed will change
94 messages · Page 1 of 1 (latest)
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
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
sorry thats gone over my head how would i apply that
Youch
Welp
I'll try type out a while scriot ig 🥱
Am on mobile
Lemme try either way
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
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
if game.UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) and game.Players.LocalPlayer
Why that
if input.KeyCode == Sprint_Key then
instead of just that
Because input
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
Send me ur whole script rn
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)
Try RunService.RenderStepped
where
Cuz you alr have a run service variable
ye the variable i added
Change from game.RunService.RenderStepped to RunService.RenderStepped
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
Put an if before that
Workspace.wandkeeper.Sprint_Script:30: Incomplete statement: expected assignment or a function call
Btw is the original script AI?
Oh wow
why
Thats long lol
For someone who doesn't code 1 hour is actually fast
XD
cuz cs education in UK is useless
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?
im checking the move direction
thats where most of the hour went
Lol
since i spent most of it trying to do humanoid state
to stop the animation
then tried move direction and it worked instantly
Good Luck 👍