Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

GUI isn't actually changing size. How do I fix this script?

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

5 comments

0

It's because you're changing the StarterGui frame size, not the PlayerGui frame size :) If someone else doesn't beat me to it, ill post an answer momentarily.

0

Thanks so much! The wikis out there haven't been super clear about the difference.

0

You're quite welcome

0

Wait can you actually post a solution because I'm not entirely sure how to script it differently. Thanks

0

lol I gotchu

2 answers

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!

4 comments

0

I've got the first few vars set up the way you have them set up, and the error message is "attempt to index local "Player" (a nil value). Thoughts?

0

umm, mind posting the code?

0

It's right below your current answer (I can delete later)

0

lol, that's not your code, that's the error

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

This discussion is preserved as it was. New answers, comments, and votes are closed.