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()
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?