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 6 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.

local barSize = script.Parent.Size
local barC = script.Parent.BackgroundColor3


while wait(1) do

function changeSize()
    local player = game.Players.PlayerAdded:connect(function(player)
        print("debug 1")
        if player.Health ~= 100 then
            player.barSize = player.Health * 10
            print("debug2")
        end
end)
end
end

changeSize()

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
6 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 — 6y
0
I mean your Objects, so that I can assist you in making this work as you expect. adark 5487 — 6y
Ad

Answer this question