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

Gui doesn't work in game, but works in roblox studio. How could i fix it?

Asked by 3 years ago
Edited 3 years ago

When i run my game in roblox studio GUI works, but when i run it at the site after published - GUI doesn't work. All scripts are local.

I tried:

Make all scripts non-local

Check scripts work with print()

Replace all StarterGUI stuff to PlayerGUI

Change GUI ZindexBehavior

Change Frame Zindex

https://ibb.co/cyc8hsS - Explorer screenshot

OpenCodesMenu script :

local GUI = script.Parent.Parent.Parent
local Frame = GUI.CodesFrame
local button = script.Parent
local hasOpen = false

GUI.Enabled = true
Frame.Position =UDim2.new(.92,0,.95,0)
Frame.Size = UDim2.new({0.05, 0},{0.08, 0})
Frame.TextBox.Text = ""
Frame.TextButton.Text = ""
Frame.TextLabel1.Text = ""
Frame.TextBox.TextSize = 0
Frame.TextButton.TextSize = 0
Frame.TextLabel1.TextSize = 0
Frame.TextLabel1.Size = UDim2.new(0,0,0,0)
Frame.TextBox.Size = UDim2.new(0,0,0,0)
Frame.TextButton.Size = UDim2.new(0,0,0,0)

        Frame.TextBox.BackgroundTransparency = 1
        Frame.TextButton.BackgroundTransparency = 1
        Frame.TextLabel1.BackgroundTransparency = 1
        Frame.BackgroundTransparency = 1

            Frame.TextBox.Visible = false
            Frame.TextButton.Visible = false
            Frame.TextLabel1.Visible = false


button.MouseButton1Click:Connect(function()

    if not hasOpen then
        Frame:TweenPosition(UDim2.new(.5,0,.5,0))
        Frame:TweenSize(UDim2.new(.3,0,.4,0))
        Frame.TextBox:TweenSize(UDim2.new(.6,0,.2,0))
        Frame.TextButton:TweenSize(UDim2.new(.3,0,.15,0))
        Frame.TextBox.Text = "ENTER YOUR CODE"
        Frame.TextButton.Text = "REDEEM"
        Frame.TextLabel1.Text = "TWITTER CODES"
        hasOpen = true

        spawn(function()
            for i = 1, 10, 1 do 
                Frame.TextBox.BackgroundTransparency -= 0.1
                Frame.TextButton.BackgroundTransparency -= 0.1
                Frame.BackgroundTransparency -= 0.1
                Frame.TextLabel1.BackgroundTransparency -= 0.1
                wait(.1)

                if i == 1 then
                    Frame.TextBox.Visible = true
                    Frame.TextButton.Visible = true
                    Frame.TextLabel1.Visible = true 
                end
            end
        end)

        spawn(function()
            for i = 1, 22, 1 do 
                Frame.TextBox.TextSize += 1
                Frame.TextButton.TextSize += 1
                Frame.TextLabel1.TextSize += 1
            end
        end)

    else if hasOpen then
            Frame:TweenPosition(UDim2.new(.92,0,.95,0))
            Frame:TweenSize(UDim2.new({0.05, 0},{0.08, 0}))
            Frame.TextBox.Text = ""
            Frame.TextButton.Text = ""
            Frame.TextBox:TweenSize(UDim2.new(0,0,0,0))
            Frame.TextButton:TweenSize(UDim2.new(0,0,0,0))

            spawn(function()
                for i = 1, 10, 1 do 
                    Frame.TextBox.BackgroundTransparency += 0.1
                    Frame.TextButton.BackgroundTransparency += 0.1
                    Frame.BackgroundTransparency += 0.1
                    wait(.1)

                    if i == 10 then
                        Frame.TextBox.Visible = false
                        Frame.TextButton.Visible = false
                        Frame.TextLabel1.Visible = false
                    end
                end
            end)

            spawn(function()
                for i = 1, 22, 1 do 
                    Frame.TextBox.TextSize -= 1
                    Frame.TextButton.TextSize -= 1
                    Frame.TextLabel1.TextSize -= 1
                end
            end)

            hasOpen = false
        end
    end

end)

OpenMenuStats script :

local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local PlayerUI = PlayerGui.PlayerUI
local button = PlayerUI.Buttons.Stats
local statsMenu = PlayerUI.StatsFrame
local hasOpen = false

PlayerUI.Enabled = true
statsMenu.Position = UDim2.new(2,0,.5,0)

button.MouseButton1Click:Connect(function()

    if not hasOpen then
        hasOpen = true
        statsMenu.Visible = true
        statsMenu:TweenPosition(UDim2.new(.8,0,.5,0))
    else if hasOpen then
            hasOpen = false
            statsMenu:TweenPosition(UDim2.new(2,0,.5,0))
            spawn(function()
                wait(1)
                statsMenu.Visible = true
            end)
        end
    end
end)

1 answer

Log in to vote
0
Answered by 3 years ago
--i have found that sometimes, guis may not load instantly. this usually requires you to use waitforchild on variables that are declaring a gui instance such as:

local PlayerUI = PlayerGui.PlayerUI
local button = PlayerUI.Buttons.Stats
local statsMenu = PlayerUI.StatsFrame

-- change the above lines and any other gui-declaring variable to:

--[[
local instance = PlayerGui:WaitForChild("INSTANCENAME")
]]

-- in the case i showed the first time you would change it to:

local PlayerUI = PlayerGui:WaitForChild("PlayerUI")
local button = PlayerUI:WaitForChild("Buttons"):WaitForChild("Stats")
local statsMenu = PlayerUI:WaitForChild("StatsFrame")

-- if the solution above does not work, check the .visible property on the UI elements and check output for any errors by pressing f9 
Ad

Answer this question