I'm coding a depleting oxygen bar. This code runs fine and depletes the variable value. The new size even prints properly, but for some reason, the GUI Frame isn't changing size when I hit play despite the fact that its size value is actively changing. I've tried local variables too, and that hasn't worked either. Any ideas?
value = 100 player = game.Players.LocalPlayer oxygen = game.StarterGui.OxygenStat.Oxygen while value > 0 do --continually depletes oxygen wait(1) value = value - 1 oxygen.Size = UDim2.new(0,value,0,15) print(oxygen.Size) end
Alright so, I know this isn't part of your question, but consider it a bonus lol
StarterGui -- Everything within it gets cloned into every player's PlayerGui who joins the game Therefore 'StarterGui' is basically useless when messing with guis (not including a bit more advanced stuff and stuff that has nothing to do with what you're wanting lol)
PlayerGui -- This is what you're wanting, this is where you'll be able to change things..
Not much of an explanation, but hopefully you get the point...
anyways,
I just made an example model for you
Insert a ScreenGui within the StarterGui -- Name the ScreenGui 'Oxygen'
Insert a frame within the ScreenGui -- Make sure the name of the Frame is 'Frame'
I'd recommending changing the First 0 and the Third 0, which is what I do within this example UDim2.new(0,0,0,0) -- I have this frame the size of UDim2.new(.6,0,.1,0)
Insert a new frame inside of that old Frame -- Name this frame 'Bar' set 'Bar' Size to UDim2.new(0,0,,0,0) -- It will be changed immediately
local value = 100 local Player = game:GetService('Players').LocalPlayer local PlayerGui = Player:WaitForChild('PlayerGui') local OxygenFrame = PlayerGui:WaitForChild('Oxygen').Frame while value > 0 do --continually depletes oxygen wait(1) value = value - 1 OxygenFrame.Bar:TweenSize(UDim2.new(value/100,0,1,0),'Out','Quad',.05) end
Any questions, feel completely free to ask!
Here's my current code. The structure in game is as follows: StarterGui > OxygenStat (ScreenGui) > Oxygen (Frame) > Bar (Frame)
local player = game:GetService('Players').LocalPlayer -- waits for loaded player local playergui = player:WaitForChild("PlayerGui") local bar = playergui:WaitForChild("OxygenStat").Oxygen.Bar local value = 100 while value > 0 do --continually depletes oxygen wait(1) value = value - 1 print(value) bar.Size = UDim2.new(0,value,0,15) print(bar.Size) end