#Running script

34 messages · Page 1 of 1 (latest)

mint walrus
#
-- Services
local UserInputService = game:GetService('UserInputService')
local players = game:GetService('Players')

-- value things
local SprintWalkSpeed = 22
local NormalWalkSpeed = 16
local DoubleTapThreshold = 0.3 


local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local status = character:WaitForChild("Status")

-- Animation
local runAnimation = character:WaitForChild("Animate").run.RunAnim
local runAnimationTrack = humanoid:LoadAnimation(runAnimation)

-- the player statuses
local lastWPressTime = 0
local isRunning = false
local isInAir = false
#
-- Helper functions
local function isAnyAttributeTrue(attributes)
    for _, attribute in ipairs(attributes) do
        if status:GetAttribute(attribute) == true then
            return true
        end
    end
    return false
end

local function startRunning()
    if not isRunning and not isAnyAttributeTrue({
        -- lists of the attributes, change if like you add a new attribute
        "Stunned",
        "Attacking",
        "Blocking",
        "Ragdoll",
        "M1Value",
        }) then
        runAnimationTrack:Play()
        humanoid.WalkSpeed = SprintWalkSpeed
        isRunning = true
    end
end

local function stopRunning()
    if isRunning then
        runAnimationTrack:Stop()
        humanoid.WalkSpeed = NormalWalkSpeed
        isRunning = false
    end
end

UserInputService.InputBegan:Connect(function(inputObject)
    if inputObject.KeyCode == Enum.KeyCode.W then
        local currentTime = tick()
        local timeSinceLastPress = currentTime - lastWPressTime
        local autoRun = status:GetAttribute("AutoRun")

        if isAnyAttributeTrue({"Stunned", "Attacking"}) then
            stopRunning() 
            return
        end

        if autoRun then
            startRunning()
        elseif timeSinceLastPress <= DoubleTapThreshold then
            startRunning()
        end

        lastWPressTime = currentTime
    end
end)

#
UserInputService.InputEnded:Connect(function(inputObject)
    if inputObject.KeyCode == Enum.KeyCode.W then
        stopRunning()
    end
end)


local function onStateChanged(_, newState)
    if newState == Enum.HumanoidStateType.Freefall or newState == Enum.HumanoidStateType.Jumping then
        if not isInAir then
            runAnimationTrack:AdjustSpeed(0.2)
            isInAir = true
        end
    elseif newState == Enum.HumanoidStateType.Running or newState == Enum.HumanoidStateType.RunningNoPhysics then
        if isInAir then
            runAnimationTrack:AdjustSpeed(1)
            isInAir = false
        end
    end
end

humanoid.StateChanged:Connect(onStateChanged)

player.CharacterAdded:Connect(function(newCharacter)
    character = newCharacter
    humanoid = character:WaitForChild("Humanoid")
    status = character:WaitForChild("Status")
    runAnimation = character:WaitForChild("Animate").run.RunAnim
    runAnimationTrack = humanoid:LoadAnimation(runAnimation)
    isRunning = false
    isInAir = false
    humanoid.WalkSpeed = NormalWalkSpeed
    humanoid.StateChanged:Connect(onStateChanged)
end)
#

couldnt fit the script in one message cause i dont got nitro

delicate carbon
atomic field
#

Bro got tsbs map of the toolbox ☠

mint walrus
atomic field
#

How though

mint walrus
#

its a other persons game called "tsb concepts"

atomic field
#

I feel bad for tsb though

#

All their assets are in the marketplace

#

But I can fix yo issue

mint walrus
#

yea I need help with this issue

atomic field
#

So when you hold w and s you don't want the anim to play?

mint walrus
#

yea

atomic field
#

Try put this at the bottom of your script:

#
game.RunService.Heartbeat:Connect(function()
    if humanoid.MoveDirection.Magnitude <= 0 then
    runAnimationTrack:Stop()
   end
end
#

Sorry I'm on mobile

#

It should work

mint walrus
#

Alr, ill try it out

#

Ill let you know if it doesnt work or if it does work

atomic field
#

Ok

atomic field
mint walrus
#

waiting for the owner to give me a response, sorry for the wait 😭

atomic field
#

Ok np

mint walrus
atomic field
#

Yup

mint walrus
#

oh alr

mint walrus
#

some reason it still plays the animation'

atomic field
#

Idk :/

#

Any console errors?

mint walrus
atomic field
#

Ye I honestly don't know