It checks the players health and gives different texts for different levels, it is meant to replace the health bar completely to make the game more challenging, I have glitched it to where I could keep walking after checking my health a few times, and I would like to add an animation but studio is down for me right now.
Any optimization or making the script more readable etc would be nice advice as well, I feel like there is something to get rid of all those tweens but I am not sure.
local plr = game:GetService("Players").LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local GUI = game.StarterGui
local MENU = game.Players.LocalPlayer.PlayerGui
local TweenService = game:GetService('TweenService')
local function tweenMax()
local Max = MENU["Full Health"].TextLabel
TweenService:Create(
Max,
TweenInfo.new(.5),
{TextTransparency = 0}
):Play()
wait(2)
TweenService:Create(
Max,
TweenInfo.new(.5),
{TextTransparency = 1}
):Play()
end
local function tweenScratch()
local Scratch = MENU.Scratch.TextLabel
TweenService:Create(
Scratch,
TweenInfo.new(.5),
{TextTransparency = 0}
):Play()
wait(2)
TweenService:Create(
Scratch,
TweenInfo.new(.5),
{TextTransparency = 1}
):Play()
end
local function tweenHalf()
local Half = MENU.Half.TextLabel
TweenService:Create(
Half,
TweenInfo.new(.5),
{TextTransparency = 0}
):Play()
wait(2)
TweenService:Create(
Half,
TweenInfo.new(.5),
{TextTransparency = 1}
):Play()
end
local function tweenQuarter()
local Quarter = MENU.Quarter.TextLabel
TweenService:Create(
Quarter,
TweenInfo.new(.5),
{TextTransparency = 0}
):Play()
wait(2)
TweenService:Create(
Quarter,
TweenInfo.new(.5),
{TextTransparency = 1}
):Play()
end
local function tweenDanger()
local Danger = MENU.Danger.TextLabel
TweenService:Create(
Danger,
TweenInfo.new(.5),
{TextTransparency = 0}
):Play()
wait(2)
TweenService:Create(
Danger,
TweenInfo.new(.5),
{TextTransparency = 1}
):Play()
end
local debounce = false
UIS.InputBegan:Connect(function(input, gpe)
if gpe or debounce then return end
if input.KeyCode == Enum.KeyCode.Q and Humanoid.Health == 100 then
debounce = true
print("I'm not hurt.")
Humanoid.WalkSpeed = 0
tweenMax()
elseif input.KeyCode == Enum.KeyCode.Q and Humanoid.Health >= 80 then
debounce = true
print("Just a scratch.")
Humanoid.WalkSpeed = 0
tweenScratch()
elseif input.KeyCode == Enum.KeyCode.Q and Humanoid.Health >= 60 then
debounce = true
print("I'll be alright.")
Humanoid.WalkSpeed = 0
tweenHalf()
elseif input.KeyCode == Enum.KeyCode.Q and Humanoid.Health >= 30 then
debounce = true
print("I should be careful!")
Humanoid.WalkSpeed = 0
tweenQuarter()
elseif input.KeyCode == Enum.KeyCode.Q and Humanoid.Health >= 0 then
debounce = true
print("I need to get to safety!")
Humanoid.WalkSpeed = 0
tweenDanger()
end
task.wait(3)
Humanoid.WalkSpeed = 16
debounce = false
end)