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

My ScreenGui Works Great In Roblox Studio, But Garbage While Playing Game Outside Studio?

Asked by 9 years ago

Thank you for looking at my question, I'll just jump straight into it,

My Problem

As you already guessed, my ScreenGui works amazingly in studio test mode. All the text buttons appear and work as well. When I get into a game outside of studio however, it does not work. I looked over the local script inside the frame of the ScreenGui, but nothing odd jumps out at me. I tried adding if game.Player.LocalPlayer (function) thenbut that didn't work either, probably added the code in wrong or something more obvious.

The Script

I have a feeling that the code's error is between lines 1 and 20. Since that function isn't working at all. Here's the code that's inside local script.

WARNING THE CODE IS VERY LONG!

local Player = game.Players.LocalPlayer--Begining Of Variables
local Menu = script.Parent
local Play = Menu.Play
local About = Menu.About
local HasPressedPlay = false
local Info = script.Parent.Info
local Minimize = Info.Minimize
local DRG = script.Parent["Dark Realm Games"]
local DRG2 = script.Parent.DRG
local Minimize2 = DRG2.Minimize
local BottomLine = script.Parent["Bottom Line"].Line
local TopLine = script.Parent["Top Line"].Line2
local DRGImage = script.Parent["Bottom Line"].DRG --End Of Variables

function MouseEnterPlayButton()--Begining Of Functions
    Play.FontSize = "Size36"
    Play.Size = UDim2.new(0, 200, 0, 80)
end

function MouseLeftPlayButton()
    --170, 0, 0 Color
    --{0, 200},{0, 50} Size
    Play.FontSize = "Size24"
    Play.Size = UDim2.new(0, 200, 0, 50)
end

function MouseEnterDRGButton()
    DRG.FontSize = "Size36"
    DRG.Size = UDim2.new(0, 200, 0, 80)
end

function MouseLeftDRGButton()
    DRG.FontSize = "Size24"
    DRG.Size = UDim2.new(0, 200, 0, 50)
end


function MouseEnterAboutButton()
    About.FontSize = "Size36"
    About.Size = UDim2.new(0, 200, 0, 80)
end

function MouseLeftAboutButton()
    --170, 0, 0 Color
    --{0, 200},{0, 50} Size
    About.FontSize = "Size24"
    About.Size = UDim2.new(0, 200, 0, 50)
end

function PlayGame()
    if HasPressedPlay == false then
        for GuiMove = 1, 30 do
            if GuiMove <= 30 then
                   Play.Position = Play.Position -UDim2.new(0.05, 0, 0, 0)
            end
            if GuiMove <= 30 then
                   About.Position = About.Position -UDim2.new(0.05, 0, 0, 0)
            end
            if GuiMove <= 30 then
                DRG.Position = DRG.Position -UDim2.new(0.05, 0, 0, 0)
            end
            if GuiMove <= 30 then
                Info.Position = Info.Position -UDim2.new(0.05, 0, 0, 0)
                end
            if GuiMove<= 30 then
                BottomLine.Position = BottomLine.Position - UDim2.new(0.05, 0, 0, 0)
                DRGImage.Position = DRGImage.Position - UDim2.new(0.05, 0, 0, 0)
            end
            if GuiMove<= 30 then
                TopLine.Position = TopLine.Position - UDim2.new(0.05, 0, 0, 0)
            end
            wait()
        end
            Menu:Destory()
        end
end
function MinimizeInfo()
    Info:TweenSizeAndPosition(UDim2.new(0, 0, 0, 0), UDim2.new(0, 0, 0, 0))
end

function Minimize2DRG()
    DRG2:TweenSizeAndPosition(UDim2.new(0, 0, 0, 0), UDim2.new(0 ,0, 0, 0))
end

function DRGPopUp()
    if DRG2.Visible == true then
        DRG2:TweenSizeAndPosition(UDim2.new(0, 400, 0, 200), UDim2.new(0.8, 0, 0.4, 0))
    else
        DRG2:TweenSizeAndPosition(UDim2.new(0, 0, 0, 0), UDim2.new(0, 0, 0, 0))
        end
    end

function InfoPopUp()
    if Info.Visible == true then
        Info:TweenSizeAndPosition(UDim2.new(0, 200, 0, 200), UDim2.new(0.8, 0, 0.4, 0))
        else
        Info:TweenSizeAndPosition(UDim2.new(0, 0, 0, 0), UDim2.new(0, 0, 0, 0))
     end
end --End Of Functions

Minimize.MouseButton1Down:connect(MinimizeInfo) --Repeating Code To Have It Processed

Minimize2.MouseButton1Down:connect(Minimize2DRG)

About.MouseButton1Down:connect(InfoPopUp)

About.MouseLeave:connect(MouseLeftAboutButton)
About.MouseEnter:connect(MouseEnterAboutButton)

Play.MouseLeave:connect(MouseLeftPlayButton)
Play.MouseEnter:connect(MouseEnterPlayButton)

Play.MouseButton1Down:connect(PlayGame)

DRG.MouseEnter:connect(MouseEnterDRGButton)
DRG.MouseButton1Down:connect(DRGPopUp)
DRG.MouseLeave:connect(MouseLeftDRGButton) --End Of Processing Code

So...

I believe the error is between (And Like I said) Around the first function. So can you guys help me? Thanks!

1 answer

Log in to vote
2
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

Gui elements don't load online like they do offline. When you index things like script.Parent.Info at the start of the script, it is entirely possible that it doesn't exist yet. Instead, each initial reference should be through WaitForChild (ex. script.Parent:WaitForChild("Info")) so that the script waits for the object to exist before continuing.

0
So basically for every function I should put script.Parent:WaitForChild("Info") (except the info) on all of them? GreekGodOfMLG 244 — 9y
0
You only need to wait for it once. After that, you know it exists and don't have to wait for it a second time (unless you mean from another script; it would also have to wait for it). 1waffle1 2908 — 9y
0
So at the start of the variables pretty much correct? GreekGodOfMLG 244 — 9y
0
Yes, each initial reference. 1waffle1 2908 — 9y
0
Aweosme thanks you! GreekGodOfMLG 244 — 9y
Ad

Answer this question