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

My Local Script To Make A ScreenGui WIith A TextButton Not Working?

Asked by 9 years ago

Thank you for viewing my question, I'm in need of help. I recently made a Local Script that makes a ScreenGui with a TextButton inside of the ScreenGui. I get an error at the 2nd line of the code, I marked out the code with little notes to help you guys solve my problem.

local SG = Instance.new([[ScreenGui]])--Make it more simple
SG.Parent = [[StarterGui]]--Parent is the StarterGui, also where I'm getting my error
local TB = Instance.new([[TextButton]])--Make it more simple
TB.Parent = [[SG]]--The new ScreenGui I made

TB.BackgroundColor3 = Color3.new(0,0,0)--Jet Black Color
TB.Transparency = 0.7--Transparency is set to this to add detail
TB.TextColor3 = Color3.new(197,0,0)--Darkish Red
TB.Font = [[Legacy]]--Favorite Font
TB.FontSize = [[Size12]]--So that it doesn't overlap the TextButton
TB.Text = [[Hello There!]]--My Message
TB.Position = UDim2.new(0.4,0,0.4,0)--Middle of the screen
function onClicked()--If the player clicks my TextButton
    TB.Text = [[Welcome to my place]]..game.Players.LocalPlayer.Name..[[!]]--The new text!
end--Since it's a function, it needs an end
script.Parent.MouseButton1Click:connect(onClicked)--Repeating code

So I get an error saying that the Parent is a bad argument, here's the error; Players.Player.PlayerGui.LocalScript:2: bad argument #3 to 'Parent' (Object expected, got string) I'm not sure what to do now, I tried editing the 2nd line of code and even the first one, but it's still not working. Is this another Roblox Studio update that's making this harder for us? And if so what can I do to make sure this doesn't happen again. Thanks for viewing my question!

0
The Parent property isn't a string, it's an object. Therefore, you must index it like you index any other objects. SG.Parent = game.StarterGui funyun 958 — 9y

1 answer

Log in to vote
2
Answered by 9 years ago

Using funyun's answer, it needs to be an object value not a string.


Set up

  1. Insert a screen gui into StarterGui
  2. Insert a textbutton into the screen gui
  3. add this script into the screen gui.

Final Product

local TB = script.Parent.TextButton

TB.BackgroundColor3 = Color3.new()--Color3.new() is the same as Color3.new(0,0,0)
TB.Transparency = 0.7--Transparency is set to this to add detail
TB.TextColor3 = Color3.new(197/255)--Darkish Red; divide 197 by 255. I deleted the other 2 last values, since they're blank it will be 0 by default.
TB.Font = [[Legacy]]--Favorite Font
TB.FontSize = [[Size12]]--So that it doesn't overlap the TextButton
TB.Text = [[Hello There!]]--My Message
TB.Position = UDim2.new(0.4,0,0.4,0)--Middle of the screen
TB.MouseButton1Down:connect(function()
    TB.Text = [[Welcome to my place]]..game.Players.LocalPlayer.Name..[[!]]
end)

Hope it helps!

Ad

Answer this question