Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why won't my gui set it's transparency to 0?

Asked by 5 years ago

I'm trying to make a functioning openable gui but nothing happens??

script.Parent.MouseButton1Click:Connect(function()
script.Parent.BackgroundTransparency = 1
script.Parent.TextTransparency = 1
game.StarterGui.ScreenGui.moveli.Frame.BackgroundTransparency = 0
game.StarterGui.ScreenGui.moveli.TextLabel.BackgroundTransparency = 0
game.StarterGui.ScreenGui.moveli.TextLabel1.BackgroundTransparency =0
game.StarterGui.ScreenGui.moveli.TextLabel2.BackgroundTransparency = 0
game.StarterGui.ScreenGui.moveli.TextLabel3.BackgroundTransparency = 0
game.StarterGui.ScreenGui.moveli.TextLabel4.BackgroundTransparency = 0
game.StarterGui.ScreenGui.moveli.TextLabel5.BackgroundTransparency = 0
game.StarterGui.ScreenGui.moveli.TextLabel6.BackgroundTransparency = 0
game.StarterGui.ScreenGui.moveli.TextLabel.TextTransparency = 0
game.StarterGui.ScreenGui.moveli.TextLabel2.TextTransparency = 0
game.StarterGui.ScreenGui.moveli.TextLabel3.TextTransparency = 0
game.StarterGui.ScreenGui.moveli.TextLabel4.TextTransparency = 0
game.StarterGui.ScreenGui.moveli.TextLabel5.TextTransparency = 0
game.StarterGui.ScreenGui.moveli.TextLabel6.TextTransparency = 0
game.StarterGui.ScreenGui.moveli.TextLabel1.TextTransparency = 0
end)

I set the properties of them to 1 beforehand

2 answers

Log in to vote
0
Answered by
gskw 1046 Moderation Voter
5 years ago

The reason why it doesn't work is due to a confusion between PlayerGui and StarterGui. StarterGui can be though of as a "template"; when a Player joins the game, everything in StarterGui will be copied to that Player's PlayerGui. Making changes to StarterGui won't affect what is currently being drawn on the player's screen. What you actually need to do is change the GUI that is in their PlayerGui, like so:

local playerGui = game.Players.LocalPlayer.PlayerGui -- PlayerGui is like a copy of game.StarterGui
local screenGui = playerGui.ScreenGui

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.BackgroundTransparency = 1
    script.Parent.TextTransparency = 1
    screenGui.moveli.Frame.BackgroundTransparency = 0
    screenGui.moveli.TextLabel.BackgroundTransparency = 0
    screenGui.moveli.TextLabel1.BackgroundTransparency =0
    screenGui.moveli.TextLabel2.BackgroundTransparency = 0
    screenGui.moveli.TextLabel3.BackgroundTransparency = 0
    screenGui.moveli.TextLabel4.BackgroundTransparency = 0
    screenGui.moveli.TextLabel5.BackgroundTransparency = 0
    screenGui.moveli.TextLabel6.BackgroundTransparency = 0
    screenGui.moveli.TextLabel.TextTransparency = 0
    screenGui.moveli.TextLabel2.TextTransparency = 0
    screenGui.moveli.TextLabel3.TextTransparency = 0
    screenGui.moveli.TextLabel4.TextTransparency = 0
    screenGui.moveli.TextLabel5.TextTransparency = 0
    screenGui.moveli.TextLabel6.TextTransparency = 0
    screenGui.moveli.TextLabel1.TextTransparency = 0
end)

Protip: you can use for loops to help with making your code easier to maintain. When you have code where you must do the same action for a large number of similar objects, you can do something like this:

local playerGui = game.Players.LocalPlayer.PlayerGui
local screenGui = playerGui.ScreenGui

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.BackgroundTransparency = 1
    script.Parent.TextTransparency = 1

    for i = 1, 6 do
        screenGui.moveli["TextLabel" .. tostring(i)].BackgroundTransparency = 0
        screenGui.moveli["TextLabel" .. tostring(i)].TextTransparency = 0
    end

    screenGui.moveli.TextLabel.TextTransparency = 0
    screenGui.moveli.TextLabel.BackgroundTransparency = 0
    screenGui.moveli.Frame.BackgroundTransparency = 0
end)
Ad
Log in to vote
0
Answered by 5 years ago

Try using script.Parent instead of game.StarterGui.

Answer this question