Ad
Log in to vote
0

how do I make the script running detect the players speed thats being changed from another script?

Asked by 6 days ago

I want it to detect the speed 8 and make it stop the running and cancel the animation but I can't figure out how to do it without breaking the script

local camera = game.Workspace.CurrentCamera

local TweeningService = game:GetService("TweenService")

local UIS = game:GetService('UserInputService')

local Bar = script.Parent:WaitForChild('STMBackground'):WaitForChild('Bar')

local player = game.Players.LocalPlayer

local NormalWalkSpeed = 16
local NewWalkSpeed = 24

local power = 10

local sprinting = false

repeat wait() until game.Players.LocalPlayer.Character

local character = player.Character


UIS.InputBegan:connect(function(key, gameProcessed)
    if key.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false then
        sprinting = true
        character.Humanoid.WalkSpeed = NewWalkSpeed
          local Anim = Instance.new('Animation')
        Anim.AnimationId = 'rbxassetid://6175401420'
        PlayAnim = character.Humanoid:LoadAnimation(Anim)
        PlayAnim:Play()
        while power > 0 and sprinting do
            power = power - .03
            Bar.Size = UDim2.new(power / 10, 0, 1, 0)
            --Bar.BackgroundColor3 = Bar.BackgroundColor3:lerp(Color3.fromRGB(255, 42, 42), 0.001)
            wait()
            if power <= 0 then
                character.Humanoid.WalkSpeed = NormalWalkSpeed
                PlayAnim:Stop()
            end
        end
    end
end)

UIS.InputEnded:connect(function(key, gameProcessed)
    if key.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false then
        sprinting = false
        character.Humanoid.WalkSpeed = NormalWalkSpeed
        PlayAnim:Stop()
        while power < 10 and not sprinting do
            power = power + .03
            Bar.Size = UDim2.new(power / 10, 0, 1, 0)
            --Bar.BackgroundColor3 = Bar.BackgroundColor3:lerp(Color3.fromRGB(255, 166, 11), 0.001)
            wait()
            if power <= 0 then
                character.Humanoid.WalkSpeed = NormalWalkSpeed
                PlayAnim:Stop()
            end
        end
    end
end)

1 answer

Log in to vote
0
Answered by 6 days ago
game.Workspace.Player.Humanoid.Running:Connect(function(speed) --detect when humanoid is running and get its speed
    if speed > 0 and speed < 16 then --the speed will not always equal exactly 8 so you want to check if it's around 8
        --script here when player's speed is 8
    else
        --script here when it isn't
    end
end)
Ad

Answer this question