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
local character = Tool.Parent local player = game.Players:GetPlayerFromCharacter( character ) local thirst = player.PlayerGui.Thirst if (thirst ~= nil) then thirst.BG.Bar.Size = UDim2.new(1, 0, 1, 0)
Well if you want to make the bar go lower, you would do something like this
local maxthirst = 100 --create a max thirst value local currentthirst = 100 --create a currentthirst value local currentthirstpercent = currentthirst/maxthirst --divide currentthirst by maxthirst to create a value between 0 and 1 to represent the percentage of thirst left. function updatebar() --a function that will update the thirst bar. run this whenever you change the thirst local currentthirstpercent = currentthirst/maxthirst --re-divides the thirst values thirst.BG.Bar.Size = UDim2.new(currentthirstpercent,0,1,0) --sets the size in the x of the bar to the percentage of thirst remaining end function drink(amount) --example function for increasing thirst currentthirst = currentthirst + amount --add thirst together if currentthirst > maxthirst then --checks to see you aren't over the max currentthirst = maxthirst --if you're over the max it sets you to the max end function updatebar() --updates the bar because you changed the value of thirst 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?