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 make a script that swaps a decal when player health is low?

Currently, I'm making an FPS game, and I made this health GUI that looks like this: https://i.imgur.com/7wohCie.png

I want to make the decal change to a red one I made when the player's health is low.

Here's my code so far:


while true do
wait(0)
script.Parent.Text = "" ..math.floor(script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.Health)
end

Pretty simple

1 answer

Hi, akuma67. The answer to the question, "How do I make a script that swaps a decal when player health is low?" is pretty simple.

Since the GUI Design looks amazing :), you want to add a frame on top of it. Make it 0.5 transparency. Then add the following code inside the frame. The code is local script.

-- Declaration Section 

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local humanoid = character.Humanoid 
local playerGui = player.PlayerGui
local healthIndicator = playerGui.Health.HealthIndicator 

-- Processing Section 

humanoid.Changed:Connect(function()
	if humanoid.Health <= 50 then
		healthIndicator.BackgroundColor3 = Color3.new(255/255, 0/255, 0/255)
		print ("Low Health!")
	else 
		healthIndicator.BackgroundColor3 = Color3.new(66/255, 138/255, 66/255)
		print("You are alive!")
	end
end)


If this helped, mark as answered. Have a lovely day of coding!

2 comments

0

Do you really need to add a Gui on top of it? You could change it's image color to red.. https://puu.sh/A4VBL/f9e2298689.png

0

Here's how my GUI is set up, with your code I don't think it might work with the way I have it https://i.imgur.com/XQN1Wi7.png

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