How do you create an on screen GUI and program it to function within my game?
This may be a silly question because i just started making my game and i have no clue how.
How do you create an on screen GUI and program it to function within my game?
This may be a silly question because i just started making my game and i have no clue how.
Normally, what a lot of people do is create the GUIs first, in StarterPack, and activate them when necessary. So, for example, people might have a LocalScript in a TextButton on the side of the screen, and have a script inside of the button. When the script detects a click, it would open a Frame that would have other stuff in it that the player could interact with. The LocalScript would look similar to this,
--LocalScript in a TextButton,
local Frame = script.Parent.Parent:WaitForChild("Frame")--Define Frame
script.Parent.MouseButton1Down:connect(function(mouse)
if Frame.Visible == true then
Frame.Visible = false
else
Frame.Visible = true
end
end)
The method is harder, takes longer, and is a bit more complicated. The method, however, is needed for some situations. We'll be creating Instances with the Instance.new function. Let's first make the ScreenGui that we'll be putting everything in.
-- LocalScript in StarterGui, or ReplicatedFirst, or even StarterPack
local plr = game:GetService("Players").LocalPlayer
local plrGui = plr:WaitForChild("PlayerGui")
local ScreenGui = Instance.new("ScreenGui", plrGui)-- makes and parents
Now we need to make a Frame, and parent it the the ScreenGui
-- LocalScript in StarterGui, or ReplicatedFirst, or even StarterPack
local plr = game:GetService("Players").LocalPlayer
local plrGui = plr:WaitForChild("PlayerGui")
local ScreenGui = Instance.new("ScreenGui", plrGui)
local Frame = Instance.new("Frame", ScreenGui)-- Makes and Parents
Now we need to make the TextBox, or something else, and set some properties of the Frame.
-- LocalScript in StarterGui, or ReplicatedFirst, or even StarterPack
local plr = game:GetService("Players").LocalPlayer
local plrGui = plr:WaitForChild("PlayerGui")
local ScreenGui = Instance.new("ScreenGui", plrGui)
local Frame = Instance.new("Frame", ScreenGui)
local TextBox = Instance.new("TextBox", Frame)-- Makes and Parents
Frame.Size = UDim2.new(1,0,1,0)
Frame.BackgroundTransparency = 1
TextBox.Text = "yay, it works!"
You could of course do more with this, and add more to this. For more info, check here. The link is a tutorial the uses the above.
Good Luck!
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
See this http://wiki.roblox.com/index.php?title=GUI_Guide and this http://wiki.roblox.com/index.php?title=The_Fundamentals_of_Scripting_with_GUIs