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

Why I can't change size of part with this script?

local S = game.StarterGui.ScreenGui
local S1 = S.S1
local S2 = S.S2
local S3 = S.S3
local S4 = S.S4
local S5 = S.S5
local S6 = S.S6
local S7 = S.S7

local Part = script.Parent

if S1.Visible == true and S2.Visible == false then
	Part.Size = Vector3.new (1, 8, 1)
end

This script not work

if S1.Visible == true and S2.Visible == false then

1 comment

0

maybe the gui is the problem

4 answers

Make sure you defined Part correctly and I see a space between Vector3.new and the parenthesis, I don't know if that still works or whatever but I know every time I did Vector3, Vector2, CFrame, basically everything the parenthesis were connected to the new so just try

Part.Size = Vector3.new(1, 8, 1)

2 comments

0

No that doesn't matter, and there is quite a bit more wrong than just a syntax error.

0

that's quite hard

local S = game.StarterGui.ScreenGui
local S1 = S.S1
local S2 = S.S2
local S3 = S.S3
local S4 = S.S4
local S5 = S.S5
local S6 = S.S6
local S7 = S.S7

if S1.Visible == true then
	if S2.Visible == false then
		script.Parent.Size = Vector.new(1, 8, 1)
	end
end

try not to use too much variables. this is not tested yet so it might not work.

3 comments

0

Nope, that's the exact same as what he is doing. Using 'and' is the equivalent of having two if statements at once.

0

oh ok

0

maybe the problem is the gui it self not the script?

To begin with, StarterGui is just the storage place for all guis that are given to a player. When a player joins, all guis in StarterGui are replicated into their PlayerGui, resulting in each player having their own guis. If you want to check a specific player's PlayerGui, this must be done through a local script.

Secondly, the if statement only checks the visibility when the script first executes. If you want to check the visibility when any of the guis' visibility changes, you can use GetPropertyChangedSignal.

Thirdly, since you are moving the local script to be inside the gui (since local scripts can only run in areas local to each player), you will have to reference the part through workspace.

So, the resulting script might look something like this (if it was a LocalScript inside the ScreenGui):

local S = script.Parent

for _,Gui in pairs(S:GetChildren()) do
	if Gui:IsA("GuiObject") then
		Gui:GetPropertyChangedSignal("Visible"):Connect(function()
			if S.S1.Visible == true and S.S2.Visible == false then
				workspace.Part.Size = Vector3.new(1,8,1)
			end
		end)
	end
end

Something like this might help as an outline. It checks each gui inside the ScreenGui for visibility change, and then checks if the specific guis are visible or not when it occurs.

Hope this helps!

PlayerGui, not StarterGui.

StarterGui holds all the guis that will be replicated to the player's PlayerGui upon joining, so what the player sees on their screen are descendants of their playerGui.

Make sure this is in a LocalScript:

local player = game.Players.LocalPlayer
local pgui = player:WaitForChild('PlayerGui')
local sgui = player:WaitForChild('ScreenGui')
local S1 = sgui.S1
local S2 = sgui.S2
local S3 = sgui.S3
local S4 = sgui.S4
local S5 = sgui.S5
local S6 = sgui.S6
local S7 = sgui.S7

if S1.Visible and not S2.Visible then
       Part.Size = Vector3.new(1, 8, 1)
end

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