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

Studio into real game Error (Please Help)?

Asked by
leepko 10
8 years ago

I created a fully functioning GUI starter Menu that works PERFECTLY in studio but as soon as I boot up my project as a real game it doesn't work, can someone help if you can?

Player = game.Players.LocalPlayer
Menu = script.Parent
Play = Menu.Play
About = Menu.About
HasPressedPlay = false
Info = script.Parent.Info
Minimize = Info.Minimize
function MouseEnterPlayButton()
    Play.FontSize = "Size36"
    Play.Size = UDim2.new(0.45, 0, 0.160, 0)
end

function MouseLeftPlayButton()
    --166, 166, 166
    Play.FontSize = "Size24"
    Play.Size = UDim2.new(0.3, 0, 0.15, 0)
end

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

function MouseLeftAboutButton()
    --166, 166, 166
    About.FontSize = "Size24"
    About.Size = UDim2.new(0.3, 0, 0.15, 0)
end

function PlayGame()
    if HasPressedPlay == false then
        for GuiMove = 1, 30 do
            if GuiMove <= 30 then           
                    Play.Position = Play.Position +UDim2.new(0.06, 0, 0, 0) 
                end
                if GuiMove <= 20 then           
                    About.Position = About.Position +UDim2.new(0.05, 0, 0, 0)   
                end
                wait()
            end

        Menu:remove()   
    end
end

function MinimizeInfo()
    Info.Visible = false
end

function InfoPopup()
    if Info.Visible == false then   
        Info.Visible = true
    else
        Info.Visible = false
    end
end

About.MouseButton1Down:connect(InfoPopup)
Minimize.MouseButton1Down:connect(MinimizeInfo)
Play.MouseLeave:connect(MouseLeftPlayButton)
Play.MouseEnter:connect(MouseEnterPlayButton)
About.MouseLeave:connect(MouseLeftAboutButton)
About.MouseEnter:connect(MouseEnterAboutButton)
Play.MouseButton1Down:connect(PlayGame)
0
Please provide the script, so we can see the problem. Pyrondon 2089 — 8y
0
Sure thing, but I don't think it's the script that's the problem as it's functioning correctly in studio leepko 10 — 8y
0
this is in a local script inside of a screen GUI in the StarterGUI folder leepko 10 — 8y
0
No output? lightpower26 399 — 8y
View all comments (7 more)
0
No? xD I wrote this on my own and just started a few days ago, all I have is wiki knowledge and a few tutorials, enlighten me leepko 10 — 8y
0
it worked fine in studio, 100% functional leepko 10 — 8y
0
Try using WaitForChild. When loading a game on a real server things have to load. So,some times the script loads before the objects the script is trying to access. So when defining your variables, use wait for child. User#11440 120 — 8y
0
In the game it shows the gui but my buttons arent working :/ leepko 10 — 8y
0
Exactly :P at the beginning of the script where you define your variables, you have to use WaitForChild. Like on line three. Try Menu:WaitForChild("Play"). If you're getting the parent though, you don't have to use wait for child because the parent load before the child. User#11440 120 — 8y
0
You also need to use WaitForChild on lines 4 6 7. User#11440 120 — 8y
0
I'll answer xD User#11440 120 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

You need to use WaitForChild.

When starting up a game on a server, things load at different time. Sometimes a script loads before the things the script is trying to access. Meaning you have to wait for the things to exist. To do this, all you have to do is use WaitForChild. You don't, however, need to use WaitForChild when accessing the parent of the script. This is because the parent loads before the children. Here's what your script would look like after making the changes,

--in local script
Player = game.Players.LocalPlayer
Menu = script.Parent
Play = Menu:WaitForChild("Play")
About = Menu:WaitForChild("About")
HasPressedPlay = false
Info = script.Parent:WaitForChild("Info")
Minimize = Info:WaitForChild("Minimize")

function MouseEnterPlayButton()
    Play.FontSize = "Size36"
    Play.Size = UDim2.new(0.45, 0, 0.160, 0)
end

function MouseLeftPlayButton()
    --166, 166, 166
    Play.FontSize = "Size24"
    Play.Size = UDim2.new(0.3, 0, 0.15, 0)
end

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

function MouseLeftAboutButton()
    --166, 166, 166
    About.FontSize = "Size24"
    About.Size = UDim2.new(0.3, 0, 0.15, 0)
end

function PlayGame()
    if HasPressedPlay == false then
        for GuiMove = 1, 30 do
            if GuiMove <= 30 then          
                    Play.Position = Play.Position +UDim2.new(0.06, 0, 0, 0)
                end
                if GuiMove <= 20 then          
                    About.Position = About.Position +UDim2.new(0.05, 0, 0, 0)  
                end
                wait()
            end

        Menu:remove()  
    end 
end

function MinimizeInfo()
    Info.Visible = false
end

function InfoPopup()
    if Info.Visible == false then  
        Info.Visible = true
    else
        Info.Visible = false
    end
end

About.MouseButton1Down:connect(InfoPopup)
Minimize.MouseButton1Down:connect(MinimizeInfo)
Play.MouseLeave:connect(MouseLeftPlayButton)
Play.MouseEnter:connect(MouseEnterPlayButton)
About.MouseLeave:connect(MouseLeftAboutButton)
About.MouseEnter:connect(MouseEnterAboutButton)
Play.MouseButton1Down:connect(PlayGame)

That looked to be the only problem. That should work. Good Luck!

0
If this doesn't work try adding a print(' ') statement after you define your variables with the WaitForChilds. If it doesn't print(' '), that's because the items your accessing doent exist. User#11440 120 — 8y
0
Testing now, moment of truth leepko 10 — 8y
0
So it worked? User#11440 120 — 8y
Ad

Answer this question