#Health Loss GUI doesn't work..
194 messages · Page 1 of 1 (latest)
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
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
Hang on, before you do, read the message again
if you ever decide?
I probably won't change it so I don't have to do the second bulletpoint
You will want to replace 100 with
human.MaxHealth
OOH
To be frank, thatâs the easier of the 2
Just for the second last line
Now as for line 8-10
Just delete those
ok
A small hint, dividing by 0 is not possible
But we wonât need those lines anyways
OH I MEANT 1
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
ResetOnSpawn?
I dont see ResetOnDeath in the GUI
It should be in the screengui instance
Healthgui is the screengui instance
it is true
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
it doesn't work when there's 1 person in a server
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
Yes, now add
human:GetPropertyChangedSignal(âHealthâ):Connect(function()
end)
aw wtf I would've never done that
Just check for any red lines in case I made a typo
Iâll explain what it means in a second, once we get it working
human:GetPropertyChangedSignal(âHealthâ):Connect(function()
end)
Wait nvm I fixed it
Wait was it a .
I had to re type it
Yes it was
No wait, it wasnât
Anyways, no red line = we typed it correctly
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
Well weâre adding a listener in to fire a function whenever the âhealthâ property changes
Go ahead and try it out
Yeah I don't really understand functions
I know the basic definition
But idk when to use them
Well this is a great example of it, whenever you wish for a line to run multiple times
E.g. right now we used one to run whenever the humanoidâs health changes
Do you have something in your game that damages the player ?
If not then type in the console
Workspace.(yourrobloxuser).Humanoid.Health -= 10
Why would I want just me to lose health
Thatâs just to test if the script works correctly
Where do I put that
In the console
I believe it opens automatically on the bottom
Itâs a text box right under the output
yeaj
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
Remove the brackets
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
I hoped it wouldnât but I know whatâs causing it
Want the easy solution or the correct one?
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
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
oh thats easy
(human.Health / human.MaxHealth) * 1
But wouldn't I have to make a script where every time you take less damage the transparency goes down
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
?
So if the transparency is 1 when I take damage how is it supposed to be shown
Youâve it mixed around. He wants it more visible as you have less health
That would cause it to always be visible unless you take damage
And the * 1 is justâŠ
eah
*yeah
@tender blaze Does it work now?
So just change the transparency to 1
and test it again
Yes
A hint, if you press arrow upwards while having the console selected then you can easily run the last command again
The transparency is 1 and its still visible đ
Hang on, mind showing the current code?
oh
I made the image transparency 1
or sorry
background transparency 1
do I make the background or image transparency 1
Happens to the best of us
ImageTransparancy
Background should also be 1 to be frank
Will it affect it
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
I made the background transparency 0 and it broke my eyes
omg its not red when I joined
before you learn studio manage on how the gui instance work
this is the part of successful game
I made my own GUI myself
Before you learn studio?
I made a loading screen and a death screen with buttons
yeah
Before you try giving advice on what people should learn first, perhaps try learning how to type it out first
i also learn how to debug and solve complex problem at stack overflow
Debugging/problem solving skills are directly tied to experience, it doesnât matter where you get it
Still interested in the listeners explanation?
Yeah
It worked
omg
yesss!!!!
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
not quite
:GetPropertyChangedSignal() is the listener
afterwards we added :Connect to connect it to a function that will fire whenever that signal gets fired
oooooh
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
So GetPropertyChangedSignal() is one of the listener
Yes
GetPropertyChangedSignal() is quite self explanatory. It retrieves the signal that gets fired when a property gets changed
Whats the difference between that and UserInputService
(Thereâs also itâs brother, .Changed() which will fire whenever any property gets changed)
UserInputService is a service. Itâs just adding a library to the script that you can then easily access
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
oh alright that makes sense
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)
So if you want something to run forever for when something happens, you use a function
Whenever something happens* yes
Ah okay
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
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
Which one?
A for loop, a while loop, a repeat loop?
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
I used this for a timer for a death screen