Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is this coding not inserting the TextLabel into the SurfaceGui?

print("hello")
function OrderStart()
	local order = game.StarterGui.Screen2.Order.Text
	local player = game.StarterGui.Screen2.PlayerName.Text
	local LabelP = Instance.new("TextLabel", game.StarterGui.SurfaceGui.Frame.PlayerFrame.PlayerList)
	LabelP.Text = player
	LabelP.TextScaled = true
	local LabelO = Instance.new("TextLabel", game.StarterGui.SurfaceGui.Frame.OrderFrame.OrderList)
	LabelO.Text = order
	LabelO.TextScaled = true
	print("done")
end

script.Parent.MouseButton1Click:Connect(OrderStart)

1 answer

✓ Accepted answer

Your using StarterGui wrong, whatever is in StarterGui will be inserted into the player's PlayerGui, so you need to do something like this:

local player = game.Players.LocalPlayer

print("hello")
function OrderStart()
    local order = player.PlayerGui.Screen2.Order.Text--Fixed line
    local player = player.PlayerGui.Screen2.PlayerName.Text--Fixed line
    local LabelP = Instance.new("TextLabel",  player.PlayerGui.SurfaceGui.Frame.PlayerFrame.PlayerList)--Fixed line
    LabelP.Text = player
    LabelP.TextScaled = true
    local LabelO = Instance.new("TextLabel",  player.PlayerGui.SurfaceGui.Frame.OrderFrame.OrderList)--Fixed Line
    LabelO.Text = order
    LabelO.TextScaled = true
    print("done")
end

script.Parent.MouseButton1Click:Connect(OrderStart)

**Just so you know, this doesn't look good, for bonus I made a better looking script.

local player = game.Players.LocalPlayer--Sets a variable for the player, note this can only be used by a LocalScript
local playerGui = player:WaitForChild("PlayerGui")--Sets a variable for the PlayerGui
local screen2 = playerGui:WaitForChild("Screen2")--Sets a variable for Screen2
local order = screen2:WaitForChild("Order")--Sets a variable for Order
local playerName = screen2:WaitForChild("PlayerName")--Sets a variable for PlayerName

local surfaceGui = playerGui:WaitForChild("SurfaceGui")--Sets a variable for SurfaceGui
local frame = surfaceGui:WaitForChild("Frame")--Sets a variable for Frame
local orderFrame = frame:WaitForChild("OrderFrame")--Sets a variable for OrderFrame
local orderList = orderFrame:WaitForChild("OrderList")--Sets a variable for OrderList

print("hello")
function OrderStart()
    local LabelP = Instance.new("TextLabel",playerName)--Fixed line
    LabelP.Text = playerName.Text
    LabelP.TextScaled = true
    local LabelO = Instance.new("TextLabel",orderList)--Fixed Line
    LabelO.Text = order.Text
    LabelO.TextScaled = true
    print("done")
end

script.Parent.MouseButton1Click:Connect(OrderStart)

For more info on StarterGui go here.

3 comments

0

Btw your script didn't work and came up with - Players.Eatcakealot.PlayerGui.Screen2.Add Order Button.LocalScript:18: bad argument #3 to 'Text' (string expected, got Object)

0

Sorry about that, I will fix it

0

Fixed it

This discussion is preserved as it was. New answers, comments, and votes are closed.