Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How Do I Disable Script When Low Health?

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)

1 comment

0

Hi, it looks like ur problem is ansewered don't forget to accept answere that wya people know this has been solved

1 answer

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!!

2 comments

0

THANKS IT WORKED YOU ARE A LIFE SAVER :D

0

Happy to help

This discussion is preserved as it was. New answers, comments, and votes are closed.