Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Healthbar not working properly?

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

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?

2 comments

0

I'm trying to make it change when a player gets hit

0

I mean your Objects, so that I can assist you in making this work as you expect.

This discussion is preserved as it was. New answers, comments, and votes are closed.