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

How do I set this TextLabel to a TextBox input?

Asked by 4 years ago

This is a LocalScript which is inside of a TextButton.

local playerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")


local n = playerGui.OrderGui.Scroll.Name.TextBox.Text

function leftClick()
    print("Left mouse click")
    playerGui.OrderGui.CurrentOrder.Text = "Vanilla Milkshake by "..n
end

script.Parent.MouseButton1Click:Connect(leftClick)

When I remove the ..n part it works fine, but nothing happens when I click the button when it has the ..n part in it.

(Excuse me as I was tired when I wrote this, I can go into further detail if you ask)

2 answers

Log in to vote
0
Answered by
7z99 203 Moderation Voter
4 years ago

Hello!

While I'm not 100% familiar with Lua textboxes, I believe I see your issue.

local playerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")

function leftClick()
    local n = playerGui.OrderGui.Scroll.Name.TextBox.Text -- Move this inside the function so it gets updated to the textbox's current text.
    print("Left mouse click")
    playerGui.OrderGui.CurrentOrder.Text = "Vanilla Milkshake by "..n
end

script.Parent.MouseButton1Click:Connect(leftClick)

0
I got an error message when I removed the ..n part. I did it for testing purposes. Here it is: Players.MinecraftButterfly87.PlayerGui.OrderGui.Flavour.Vanilla.LocalScript:5: attempt to index nil with 'Text' MinecraftButterfly87 10 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Because the TextBox was inside a frame called "Name," and "Name" is a property, that's what caused the issue.

Answer this question