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

How to make a changeable textlabel?

Asked by 8 years ago

I'm trying to make a a gui. There's a textbox on this gui that says 'ENTER TEXT HERE' and a textbutton called Submit. I am aware that when you are in game you can change the text in the textbox. This is my script that was inserted into the button SUBMIT

--By Groen Galaxy

local choosetext = game.StarterGui.ScreenGui.Frame.choosetext
local submit = script.Parent

submit.MouseButton1Down:connect(function()
    game.Workspace.Part.SurfaceGui.TextLabel.Text = choosetext.Text




end)


So the aim is that when the submit button is clicked the text that the player entered shows up on a textlabel in game.. It only shows the text that was originally set there (ENTER TEXT HERE) and not the text that the player put there... Any help would be much appriciated.

2 answers

Log in to vote
0
Answered by
Link150 1355 Badge of Merit Moderation Voter
8 years ago
Edited 8 years ago

On line #3, you set the variable choosetext to be a reference to the "choosetext" textbox located in the StarterGui. In your MouseButton1Down callback, you then set the Text property of the textlabel to whatever happens to be the value of the Text property of the object referred by your choosetext variable.

The problem is that the StarterGui service is used to contain a default gui to be copied to every player upon spawning. choosetext.Text thus evaluates to whatever text your textbox element takes by default.

What you want is to use the value of the Text property from the "choosetext" textbox from the player's PlayerGui, which is located in their Player object (e.g: game.Players.Player1.PlayerGui.ScreenGui.Frame.choosetext).

Alternatively, you could select the element relative to the script: script.Parent.Parent.choosetext.

Anyways, hope that helped. If it did, please mark my answer as accepted and optionally upvote, it helps us both. :)

Ad
Log in to vote
0
Answered by
Im_Kritz 334 Moderation Voter
8 years ago

Your local choosetext variable is the textlabel from the game.StarterGui. Meaning what the player is typing in the Gui doesn't do anything because your variable takes info from the game.StarterGui Gui, which happens to be ENTER TEXT HERE.

You need the Gui in the PlayerGui not the one you have there.

Assuming you are using a regular script and the textlabel is in the same frame as your submit button, your variable should be:

local choosetext = script.Parent.Parent.choosetext

Here's the full code:

--By Groen Galaxy

local choosetext = script.Parent.Parent.choosetext
local submit = script.Parent

submit.MouseButton1Down:connect(function()
    game.Workspace.Part.SurfaceGui.TextLabel.Text = choosetext.Text




end)

Answer this question