So I Edited part of a script from food, to make the hunger bar go up when you eat it.
It works, but I only found a way to make it so that it fills the hunger bar all the way.
So is there any way to add a certain amount to the UDim2 property of the Gui, and make it so it doesn't go above what it is normally?
This is the chunk of code where it adds full thirst
1 | local character = Tool.Parent |
2 | local player = game.Players:GetPlayerFromCharacter( character ) |
3 |
4 | local thirst = player.PlayerGui.Thirst |
5 |
6 | if (thirst ~ = nil ) then |
7 | thirst.BG.Bar.Size = UDim 2. new( 1 , 0 , 1 , 0 ) |
Well if you want to make the bar go lower, you would do something like this
01 | local maxthirst = 100 --create a max thirst value |
02 | local currentthirst = 100 --create a currentthirst value |
03 |
04 | local currentthirstpercent = currentthirst/maxthirst --divide currentthirst by maxthirst to create a value between 0 and 1 to represent the percentage of thirst left. |
05 |
06 | function updatebar() --a function that will update the thirst bar. run this whenever you change the thirst |
07 | local currentthirstpercent = currentthirst/maxthirst --re-divides the thirst values |
08 | thirst.BG.Bar.Size = UDim 2. new(currentthirstpercent, 0 , 1 , 0 ) --sets the size in the x of the bar to the percentage of thirst remaining |
09 | end |
10 |
11 | function drink(amount) --example function for increasing thirst |
12 | currentthirst = currentthirst + amount --add thirst together |
13 | if currentthirst > maxthirst then --checks to see you aren't over the max |
14 | currentthirst = maxthirst --if you're over the max it sets you to the max |
15 | end |
16 | function updatebar() --updates the bar because you changed the value of thirst |
17 | end |
This is all example and you'd need to code things like decreasing thirst values and such as well, but this is what you're asking for I think.
Locked by sgsharp and BlueTaslem
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?