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

Why doesn't my healthbar decreased when the player is damaged?

Asked by 5 years ago
Edited 5 years ago

I made a healthbar with the player's avatar with the name.I have attempted 12 times now and the healthbar doesn't decreased whenever I'm damaged. I've done the script again but it still doesn't work. When I used the Output, it said Argument 1 missing or nil.

local player = game.Players.LocalPlayer

local unitFrame = script.Parent

unitFrame:WaitForChild("Avatar").Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&username=" .. player.Name

unitFrame:WaitForChild("PlayerName").Text = player.Name

local healthBar = unitFrame.HealthBarContainer.HealthBar

player.CharacterAdded:connect(function(character)

local humanoid = character:WaitForChild(Humanoid)

humanoid.HealthChanged:Connect(function(health)

local healthPercentage = health / character.Humanoid.MaxHealth

healthBar.Size = UDim2.new(healthPercentage, 0, 1, 0)

end)

end)

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
0
which line did the error come from? starmaq 1290 — 5y
0
b a d i n d e n t a t i o n LoganboyInCO 150 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Now a days with Filtering Enabled, your health bar will only decrease if the client sees the health decrease.

I have a wild idea for you, that you should try out as it is how I did my health bar.

Go to the server side script, and add the HealthChanged event to the player's humanoid on the server side, when the health is changed, FireClient(player,"healthChanged",currentHealth,MaxHealth)

The, "healthChanged," is just how I set up my games to use 1 remote event per game, you can remove it if you don't do things that way though.

Then, add OnClientEvent to the client, and have the healthbar change it through that.

I apologize if this is a bit of a dull answer, but I get this feeling you'll get what I mean without any code involved, assuming you know how getting a player's humanoid works on the server, you should do fine.

That's how I set mine up, I'm sure there's other client ways to do so, but I had my reasons on the game for it being on the server, and I can vouch that mine works, so try it!

Ad

Answer this question