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

How do I make a script that swaps a decal when player health is low?

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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!
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 Fifkee 2017 — 6y
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 akuma67 2 — 6y
Ad

Answer this question