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

Health bar goes down in studio, doesn't budge in game?

Asked by 6 years ago

My health bar seems to be working properly in studio, but doesn't work in game. I'm not sure if this is an issue with roblox or something. Here's the code.

game.Players.LocalPlayer.Character.Humanoid.Changed:connect(function()
local redzone = game.Players.LocalPlayer.Character.Humanoid.MaxHealth/5 
if game.Players.LocalPlayer.Character.Humanoid.Health <= redzone then
script.Parent.BackgroundColor3 = Color3.new(255,0,0)
end
if game.Players.LocalPlayer.Character.Humanoid.Health > redzone then
local brickcolor = BrickColor.new("Deep orange")
local color = brickcolor.Color
script.Parent.BackgroundColor3 = color
end
script.Parent.Size = UDim2.new(game.Players.LocalPlayer.Character.Humanoid.Health / game.Players.LocalPlayer.Character.Humanoid.MaxHealth,0,0,20)
end)

Please let me know if there's anything wrong with my script or if there's a solution, thank you.

1 answer

Log in to vote
1
Answered by 6 years ago

Off the bat: if something doesn't work right, 99.99999% of the time it is you, not the game/engine/Roblox etc. Don't jump to blaming Roblox because your script doesn't work.

That said, try this (read it and learn from it):

local player = game.Players.LocalPlayer;
local humanoid = player.Character.Humanoid;
local redzone = humanoid.MaxHealth/5;

humanoid.HealthChanged:connect(function(newhealth)
    script.Parent.Size = UDim2.new(newhealth/humanoid.MaxHealth, 0, 0, 20);
    if(newhealth <= redzone)then
        script.Parent.BackgroundColor3 = Color3.fromRGB(255, 0, 0);
    else
        script.Parent.BackgroundColor3 = BrickColor.new("Deep orange").Color;
    end
end)
1
Thank you, I will try not to jump to conclusions next time, and try to find out whatever's wrong with my script. Crazykookie2 5 — 6y
Ad

Answer this question