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

Healthbar not working properly?

Asked by 7 years ago

Im working on a display healthbar on a surfaceGUI.

This is the code that doesn't print after it hits like 1/3rd of the way through.

01local barSize = script.Parent.Size
02local barC = script.Parent.BackgroundColor3
03 
04 
05while wait(1) do
06 
07function changeSize()
08    local player = game.Players.PlayerAdded:connect(function(player)
09        print("debug 1")
10        if player.Health ~= 100 then
11            player.barSize = player.Health * 10
12            print("debug2")
13        end
14end)
15end
16end
17 
18changeSize()

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
7 years ago

You're doing stuff out of order here.

The while loop is constantly redefining the changeSize function, but you only call it once. changeSize itself connects to the PlayerAdded event, so health will only update whenever a Player joins. Additionally, you define "player" outside of the anonymous function, to no effect. To be honest, I have no idea what you're trying to do here specifically.

Can you provide more detail of how you've set up your Objects?

0
I'm trying to make it change when a player gets hit KennySfromTitan 106 — 7y
0
I mean your Objects, so that I can assist you in making this work as you expect. adark 5487 — 7y
Ad

Answer this question