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

My title screen script still does not close?

Asked by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

I asked once before, and changed what was wrong, but the script still refuses to work. The problem I am having is closing the gui when a textbutton is clicked. Thanks in advance!

The script:

local titlescreen = Instance.new("ScreenGui")
titlescreen.Parent = script.Parent

-- Frame
local titleframe = Instance.new("Frame")
titleframe.Parent = titlescreen
titleframe.Position = UDim2.new(0, 75, 0, 75)
titleframe.Size = UDim2.new(0, 850, 0, 400)
titleframe.Style = "RobloxRound"

-- Text
local titletext = Instance.new("TextLabel")
titletext.Parent = titlescreen
titletext.Position = UDim2.new(0, 400, 0, 85)
titletext.Size = UDim2.new(0, 250, 0, 50)
titletext.FontSize = "Size24"
titletext.BackgroundTransparency = 1
titletext.Text = "Project Undefined"

-- Button
local titlebutton = Instance.new("TextButton")
titlebutton.Parent = titlescreen
titlebutton.Position = UDim2.new(0, 400, 0, 175)
titlebutton.Size = UDim2.new(0, 250, 0, 50)
titlebutton.FontSize = "Size14"
titlebutton.Text = "Start"

function onClicked()
    titlescreen.remove()
end

titlebutton.MouseButton1Down:connect(onClicked)

1 answer

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

remove is a method. It requires an argument, and calling it as a method automatically passes the object it was called from as the first argument: titlescreen:remove().

It is also deprecated, so write titlescreen.Parent=nil or titlescreen:Destroy() instead.

Ad

Answer this question