#Health Loss GUI doesn't work..

194 messages · Page 1 of 1 (latest)

tender blaze
#

Script.

prisma python
# tender blaze

Few notes:

  • you aren’t using any signal/loop to trigger the bar updating. so it only updates once.
  • I would use Health/MaxHealth. that will make it so you'll run into less issues if you ever decide to change the maxhealth to a different number
tender blaze
#

First, I was thinking of doing a repeat/loop but I don't know how to do that in scripting, I just started only recently.
Second off, is MaxHealth something I can replace for Health

prisma python
tender blaze
#

if you ever decide?

#

I probably won't change it so I don't have to do the second bulletpoint

prisma python
#

You will want to replace 100 with
human.MaxHealth

tender blaze
#

OOH

prisma python
#

Just for the second last line

#

Now as for line 8-10

#

Just delete those

tender blaze
#

ok

prisma python
#

A small hint, dividing by 0 is not possible

#

But we won’t need those lines anyways

tender blaze
#

OH I MEANT 1

prisma python
#

Before I continue, is this script inside starting player scripts or starting character scripts?

#

Oh wait, I see it’s inside the ui

#

Nevermind

#

In the ui, is the property ResetOnDeath = true?

#

(You can check that in the property window, it will show a cube next to it, with either a checker in it or nothing)

#

Just tell me if you get stuck at that step

tender blaze
#

I dont see ResetOnDeath in the GUI

prisma python
tender blaze
#

I dont have that

prisma python
tender blaze
#

Yeah ResetOnDeath isn't in HealthGui

prisma python
#

I guess I mixed up the name of it

tender blaze
#

it is true

prisma python
#

Okay so this tells us the script will recompile every time a new character gets added

#

Meaning we don’t have to add a function in to check for a character spawn

tender blaze
#

it doesn't work when there's 1 person in a server

prisma python
#

Sorry what?

#

The script isn’t finished yet so it wouldn’t work as of now, yes

#

We now just know we only need 1 listener (I’ll get back to that term) instead of 2

tender blaze
#

ok so this is what it looks like rn

prisma python
#

Yes, now add

human:GetPropertyChangedSignal(“Health”):Connect(function()

end)

tender blaze
#

aw wtf I would've never done that

prisma python
#

Just check for any red lines in case I made a typo

prisma python
tender blaze
#

human:GetPropertyChangedSignal(“Health”):Connect(function()

end)

#

Wait nvm I fixed it

prisma python
#

Wait was it a .

tender blaze
#

I had to re type it

prisma python
#

Yes it was

prisma python
#

Anyways, no red line = we typed it correctly

tender blaze
#

ik

#

So your making a function for the Humanoids Health

prisma python
#

Now highlight all of line 7. Press ctrl + x, highlight the line in between the 2 lines you just added. Then press ctrl + v

#

I typed it out like this as ctrl + x will be your best friend when writing code

tender blaze
#

so this?

prisma python
prisma python
tender blaze
#

Yeah I don't really understand functions

#

I know the basic definition

#

But idk when to use them

prisma python
#

E.g. right now we used one to run whenever the humanoid’s health changes

tender blaze
#

The border is red as I joined the game]

#

Full health

prisma python
#

Do you have something in your game that damages the player ?

#

If not then type in the console

Workspace.(yourrobloxuser).Humanoid.Health -= 10

tender blaze
#

Why would I want just me to lose health

prisma python
#

That’s just to test if the script works correctly

tender blaze
#

Where do I put that

prisma python
#

In the console

tender blaze
#

?

#

Console?

prisma python
#

I believe it opens automatically on the bottom

#

It’s a text box right under the output

tender blaze
#

soooo

#

is it in the script

#

??

prisma python
#

Do you see that bar on your screen?

tender blaze
#

yeaj

prisma python
#

That’s the console

#

It’s mostly used to quickly test stuff out

#

While running a test (so your character is spawned in), type the thing line I just send in there

#

It will simulate your player getting damaged

tender blaze
prisma python
#

Remove the brackets

tender blaze
#

I took health and the red bar went away

#

Once my health went back to full my screen isn't red

#

Wait...

#

It works once I put my health all the way up

#

then went back down

#

Cause my screen didn't start bright red

prisma python
#

I hoped it wouldn’t but I know what’s causing it

#

Want the easy solution or the correct one?

tender blaze
#

Yeah whenever I spawn its red

#

Whats the correct one

#

I've been trying to fix this for a while

#

i wouldn't even care if I had to scrap it

prisma python
#

Correct one would be to just stop the test and set the transparency of the ui to 1

#

As now it starts off at 0

tender blaze
#

oh thats easy

bleak yacht
tender blaze
#

But wouldn't I have to make a script where every time you take less damage the transparency goes down

prisma python
#

And easy work around for this if you want to see the ui while not in a test is to add in a line that changes the transparency to 1

tender blaze
#

So if the transparency is 1 when I take damage how is it supposed to be shown

prisma python
prisma python
#

And the * 1 is just


prisma python
#

@tender blaze Does it work now?

tender blaze
#

and test it again

prisma python
#

Yes

#

A hint, if you press arrow upwards while having the console selected then you can easily run the last command again

tender blaze
#

The transparency is 1 and its still visible 😭

prisma python
#

Hang on, mind showing the current code?

tender blaze
#

oh

#

I made the image transparency 1

#

or sorry

#

background transparency 1

#

do I make the background or image transparency 1

prisma python
#

Happens to the best of us

prisma python
#

Background should also be 1 to be frank

tender blaze
#

Will it affect it

prisma python
#

Eh, it will just look odd

#

Background transparency is the back of the image, if it’s visible then you will constantly have a white (or whatever color it is) bar on your screen

tender blaze
#

I made the background transparency 0 and it broke my eyes

prisma python
#

Yep

#

It does that

tender blaze
#

omg its not red when I joined

bleak yacht
#

before you learn studio manage on how the gui instance work

bleak yacht
tender blaze
prisma python
tender blaze
#

I made a loading screen and a death screen with buttons

bleak yacht
prisma python
# bleak yacht yeah

Before you try giving advice on what people should learn first, perhaps try learning how to type it out first

bleak yacht
#

i also learn how to debug and solve complex problem at stack overflow

prisma python
#

Debugging/problem solving skills are directly tied to experience, it doesn’t matter where you get it

prisma python
tender blaze
#

It worked

#

omg

#

yesss!!!!

prisma python
# tender blaze Yeah

So many engines (including roblox’) have events. These events are correlated to things that happen in/around the game

#

you'll be using them a lot while making games. As they allow you to make certain stuff happen when certain stuff occurs

#

we just used one of these events (also known as signals) to let us know when the player's health changes

tender blaze
#

ooh

#

Which is a function?

prisma python
#

not quite

#

:GetPropertyChangedSignal() is the listener

#

afterwards we added :Connect to connect it to a function that will fire whenever that signal gets fired

tender blaze
#

oooooh

prisma python
#

you can also use :Wait() to yield the script as we wait for the signal (which you used in line 2). These will be the main 2 you’ll be using

tender blaze
#

So GetPropertyChangedSignal() is one of the listener

prisma python
#

Yes

#

GetPropertyChangedSignal() is quite self explanatory. It retrieves the signal that gets fired when a property gets changed

tender blaze
#

Whats the difference between that and UserInputService

prisma python
#

(There’s also it’s brother, .Changed() which will fire whenever any property gets changed)

prisma python
#

Yet this library also comes with it’s own listeners to check for userinputs and such

#

As for the function, we simply declared a function (without a name, so we can’t call it in any other place). That will run whenever the signal gets fired

#

That’s one way of making functions

tender blaze
#

oh alright that makes sense

prisma python
#

The other way is

local function FunctionName()
end

Which can be fired both by calling it:

FunctionName()

Or by connected it to listeners

Part:GetPropertyChangedSignal(“Size”):Connect(FunctionName)

tender blaze
#

So if you want something to run forever for when something happens, you use a function

prisma python
tender blaze
#

Ah okay

prisma python
#

If you wish for something to keep occurring every (let’s say second) then we use a loop

#

A common example of this is the while loop

#

Yet there are also for loops, which match well with tables

#

Yet this is already diving deeper into luau

#

I would first try messing around a bit with basic listeners and functions

tender blaze
#

Can you show an example of how to use a loop

#

I was wondering that

prisma python
#

In case you’re wondering how I knew the name of the listener: I remembered it, as it’s a very common one.

But in case I don’t have it memorised then I refer to the docs

https://create.roblox.com/docs/reference/engine/classes/Instance#events
(And yes, this was a dumb listener as it’s technically a method that returns one. But you can still quickly look it up)

And if you’re keen eyed then you may noticed that humanoids also have a .HealthChanged listener. And yes that would’ve been the better option to use, yet any excuse to teach somebody the amazing GetPropertyChangedSignal listener is worth it to me

Instance is the base class for all classes in the Roblox class hierarchy.

prisma python
#

A for loop, a while loop, a repeat loop?

tender blaze
#

Repeat loop

#

One that goes on forever

prisma python
#

While and repeat can both do that

#

an example of a while loop is

while boolean do

code

end

(Boolean = either true or false, now I’ll use true so you can actually test these out)
But don’t run that, as it will try to run as fast as possible, which is not good, so let’s add in a yield

while true do
task.wait()
end

yet we can write that even smaller

while task.wait() do

end

#

repeat is easier

repeat

  • code
    until (statement that will stop loop if it equals true)
#

for loops are probably the hardest of the bunch

for i = 1, 10,1 do
end

first number is where it starts, second number is where it end, third number is the number it adds to the first number until it reaches the second number

The third number is optional so it does the same as

for i=1, 10 do
end

yet we can also integrate tables into this, like one filled with all children of the workspace
This will require us to add some variables, i = index, in our example this will be the names of the children, v will be the value that corresponds to that key. In our case the instances.

for i, v in Workspace:GetChildren() do
print(v)
end

#

For smaller loops (definitely those that don’t repeat for more than 50-100 times) you don’t really have to add in a yield, mostly just for those looping indefinitely

tender blaze