Instructions
Open Roblox Studio and open your place.
Use the Udim2 function to create a location for your GUI. For example, you can use the following code:
local r = Instance.new("Frame")
r.Position = UDim2.new(.5, 0, .5, 0)
r.Size = UDim2.new(.5, 0, .5, 0)
The "r.Position = UDim2.new(.5, 0, .5, 0)" line of code represents where the GUI will appear in your place. To move the GUI around your place, change the "(.5, 0, .5, 0)" numbers. Each number represents a coordinate; by changing the numbers you will change the location of the GUI.
Create a rectangular frame for your GUI that will appear anytime a player connects to your place. For example, use the following code:
game.Players.PlayerAdded:connect(function(Player)
local f = Instance.new("Frame")
local s = Instance.new("ScreenGui")
f.Parent = s
s.Parent = Player.PlayerGui
f.Position = UDim2.new(0.5, 0, 0.5, 0)
f.Size = UDim2.new(0.5, 0, 0.5, 0)
end)
The "game.Players.PlayerAdded:connect(function(Player)" command is what tells your GUI to initiate when a player connects to your place.
The "r.Size = UDim2.new(.5, 0, .5, 0)" represents the size of the GUI. Changing the numbers in the line of code will change the size of the GUI.
Create button inputs for your GUI. For example, use the following code:
game.Players.PlayerAdded:connect(function(Player)
local f = Instance.new("TextButton")
local s = Instance.new("ScreenGui")
f.Parent = s
s.Parent = Player.PlayerGui
f.Position = UDim2.new(0.1, 0, 0.1, 0)
f.Size = UDim2.new(0.5 0, 0.5, 0)
f.MouseButton1Down:connect(function()
print("You clicked a text GUI!")
end)
end)
The "f.MouseButton1Down:connect(function()
print("You clicked a text GUI!")
end)" code tells your GUI to output "You Clicked a text GUI" anytime the user left-clicks on the GUI. You can change the text to anything you want. You can also assign an action to the right mouse button by using the "f.MouseButton2Down" function." command.
Click "Save" to save the GUI to your place.