#Need help correctly displaying healthbar value

1 messages · Page 1 of 1 (latest)

analog olive
#

I use this script inside serverscriptservice to add a healthbar above all playerd heads, the 2nd part of the script is supposed to update the health above the players head so everyone in the server can see it when fired but the healthbar does not change.

mossy bramble
analog olive
mossy bramble
#

A script that handles movement should not also handle weapon system.

#

You can't just make one script that handles everything.

#

So make each healthbar have It's own script that handles the display on It's own,

analog olive
#

ive tried the 2nd part in a different script as well, i just cant get the healthbar do work right

#

is there something wrong with the script?

#

let me try makin a script for each healthbar

mossy bramble
#

Where does the health remote event fire from

analog olive
#

i have a local script that updates the players own healbar for just their screen gui, when the health is updated for the player it fires the sever

#

server*

mossy bramble
#

Can you show me how the health GUI is built?

analog olive
#

this is the billboard that every player sees

#

health is the healthbar

mossy bramble
#

Could you show me the insides of every frame

analog olive
#

they all just have 1 image in them

#

cause its a custom UI

#

nothing else

#

any ideas?

mossy bramble
#

And this is put inside the Players Head

#

right?

analog olive
#

yeah

mossy bramble
#

Which frame is the one displaying the health decrease and increase

#

Health?

analog olive
#

yeah

mossy bramble
#
local char = script.Parent.Parent
local hum: Humanoid = char:WaitForChild("Humanoid")
local health: Frame = script.Parent.Health
local size

hum.HealthChanged:Connect(function()
    size = math.clamp(hum.Health / hum.MaxHealth, 0, 1)
    health.Size = UDim2.new(size, 0, 1, 0)
end)
mossy bramble
#

@analog olive

analog olive
#

im testing it

#

cant quite get it to work

mossy bramble
#

how so

analog olive
#

i swap to the server side view and the healthbar just doesnt change

#

maybe im missin somethin idk

mossy bramble
#

Do u like

#

Damage the player?

#

On server side?

analog olive
#

i change the health value

mossy bramble
#

on the server?

analog olive
#

in humanoid

#

idk i just change the value in properties

vestal zodiac
analog olive
#

what do i gotta do

vestal zodiac
#

So you have to pop in server view to actually do changes that replicates to all clients

mossy bramble
#

Otherwise it wont do anything

analog olive
#

so i click on the server side view right?

mossy bramble
analog olive
#

that?

mossy bramble
#

This has to be saying "Server"

analog olive
#

then change the property?

mossy bramble
#

Yh

vestal zodiac
#

Yeah and you should be able to test if it actually works

analog olive
#

still nothin

vestal zodiac
#

Did you try printing before connecting the event and within the event? Maybe the event doesn't get connected I don't really know where your script is but the WaitForChild could make it wait infinitly

mossy bramble
#

Cuase

analog olive
#

i did try print

#

whattt

analog olive
#

in the players head?

mossy bramble
#

no its in sss

vestal zodiac
#

So just before the HealthChanged event line

mossy bramble
#

still works

#

lol

vestal zodiac
# mossy bramble

I would guess he just put the script within the billboard and didn't check the pathing

exotic pendantBOT
#

studio** You are now Level 4! **studio

vestal zodiac
#

Having a WaitForChild yield

analog olive
#

there is no infinite yield

mossy bramble
#

Or did the gui changing wrong

#

like try adding this

#
local char = script.Parent.Parent
local hum: Humanoid = char:WaitForChild("Humanoid")
local health: Frame = script.Parent.Health
local size

hum.HealthChanged:Connect(function()
    health:Destroy()
end)
#

see if it does anything

analog olive
#

nothin

#

does it matter that my GUI is cloned?

#

from replicated storage

#

and placed into the head of the player

vestal zodiac
#

If it does print, it does run

analog olive
#

it doesnt print nothin

#

i just dont even understand

vestal zodiac
#

Did you try literally printing smth at the very first line to see if it even run at all

analog olive
#

it does print in the very first line

vestal zodiac
#

Ok so print everything until you find where it stop working

#

uh

mossy bramble
#

lmfao

analog olive
#

with NOTHING

mossy bramble
#

you did it agian

analog olive
#

huh

mossy bramble
#

where the hum.HealthChanged

analog olive
#

lower

exotic pendantBOT
#

studio** You are now Level 10! **studio

analog olive
#

i just didnt show it

mossy bramble
#

oh oke

#

well uh

#

wheres the script

#

like

#

before its cloned

analog olive
#

replicated

mossy bramble
#

not inside the gui?

analog olive
#

the billboard is in replicated

mossy bramble
#

the script

analog olive
#

the script is in the gUI

mossy bramble
#

wheres the scrip

#

where in the gui

#

inside the frame

#

or the gui itself

analog olive
#

no

#

GUI

#

inside billboard

mossy bramble
#

and then you clone this billboard and

#

put it inside the head

vestal zodiac
#

But where is the script located within the billboard gui

mossy bramble
#

wait i think i have an idea

vestal zodiac
#

So like

Overheadhealth
Script

analog olive
#

ye

#

Healthchanged is not a valid member

vestal zodiac
#

You forgot to uppercase C

#

HealthChanged

mossy bramble
#

big C

analog olive
#

its printing now

vestal zodiac
#

ok great, atleast that's progress

analog olive
#

but not

#

its printed ypayapya

mossy bramble
#

its printing ypaypypa everytime?

analog olive
#

or whatever

#

yesd

#

but didnt change health

vestal zodiac
#

So now the size variable need to be in the event

#

cause

analog olive
#

change the GUI i mean

mossy bramble
vestal zodiac
#

You can't know the health ahead of time

mossy bramble
#

the size isnt changing

analog olive
#

i see

#

omgggg

#

bless ur guys soul

#

the goats

vestal zodiac
#

Just make sure to understand why it wasn't working before

analog olive
#

yeah so

mossy bramble
#

You werent changing the size value

#

it was stationary

analog olive
#

why does the variable have to be in the connect function

mossy bramble
#

cause you only defined it once

vestal zodiac
#

The function that you define within the HealthChanged connection

#

gets called each time the health changes

#

But the variable was define before the health was changed

#

Staying basically the same

analog olive
#

ohhhh

#

that makes perfect sense

vestal zodiac
#

Putting it within the event updates it

analog olive
#

thank you guys

mossy bramble
#

Like when its outside the HealthChanged its always the same

#

when its inside it changes everytime the health value is changed

analog olive
#

yeah that makes sense

mossy bramble
#

yh

analog olive