Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How Do I Disable Script When Low Health?

Asked by 2 years ago

i made a script that makes me 9 walkspeed when i reach low health. but im still able to sprinting someone please help how i disable the script when i reach low health (etc. 30 health) (when health regens script will be able again)

The Running Script :

local Player = game.Players.LocalPlayer
local Character = workspace:WaitForChild(Player.Name)
local Humanoid = Character:WaitForChild('Humanoid')

local RunAnimation = Instance.new('Animation')
RunAnimation.AnimationId = 'rbxassetid://11321538517' -- Animation ID here.
RAnimation = Humanoid:LoadAnimation(RunAnimation)

Running = false

function Handler(BindName, InputState)
    if InputState == Enum.UserInputState.Begin and BindName == 'RunBind' then
        Running = true
        Humanoid.WalkSpeed = 50
    elseif InputState == Enum.UserInputState.End and BindName == 'RunBind' then
        Running = false
        if RAnimation.IsPlaying then
            RAnimation:Stop()
        end
        Humanoid.WalkSpeed = 16
    end
end

Humanoid.Running:connect(function(Speed)
    if Speed >= 10 and Running and not RAnimation.IsPlaying then
        RAnimation:Play()
        Humanoid.WalkSpeed = 30
    elseif Speed >= 10 and not Running and RAnimation.IsPlaying then
        RAnimation:Stop()
        Humanoid.WalkSpeed = 10
    elseif Speed < 10 and RAnimation.IsPlaying then
        RAnimation:Stop()
        Humanoid.WalkSpeed = 10
    end
end)

Humanoid.Changed:connect(function()
    if Humanoid.Jump and RAnimation.IsPlaying then
        RAnimation:Stop()
    end
end)

game:GetService('ContextActionService'):BindAction('RunBind', Handler, true, Enum.KeyCode.LeftShift)
0
Hi, it looks like ur problem is ansewered don't forget to accept answere that wya people know this has been solved blue_bunny0fficl 98 — 2y

1 answer

Log in to vote
1
Answered by 2 years ago

Hi, your going to want to use an if statement and then disable the script by using Enabled code. example

if Humanoid.WalkSpeed = 10 then
script.Parent.Enabled = false

This is an example of how. It probably won't work with your code just an example. Also I think you can use <> to set less than or more than. Hope this helps!!

0
THANKS IT WORKED YOU ARE A LIFE SAVER :D esad12354 5 — 2y
0
Happy to help theking66hayday 841 — 2y
Ad

Answer this question