TextBox
A text field players can type in.
- Inherits: TextLabel → GuiObject → Instance
- Creatable: Yes:
new TextBox(), orInstance.new('TextBox', parent). - Replication: Replicated: clients get a copy, and changes the server makes reach them.
On the player’s device, typing updates text there. Pressing Enter or Escape, or clicking
elsewhere, ends editing and fires focusLost. While someone types, their key presses still reach
UserInputService, with gameProcessed set to true.
What a player types stays on their device: send it to the server with a RemoteEvent, and check it there.
Properties
Section titled “Properties”placeholderText
Section titled “placeholderText”Type: string · Default: '' · Access: read/write · Replicates: yes
Hint shown while the field is empty.
Inherited from TextLabel: text, textColor, textSize, fontWeight, textAlign, textWrapped
Inherited from GuiObject: position, positionScale, size, sizeScale, anchorPoint, backgroundColor, backgroundTransparency, cornerRadius, visible, zIndex
Inherited from Instance: name, archivable, id, className, parent, destroyed
Methods
Section titled “Methods”Inherited from Instance: getPropertyChangedSignal, setAttribute, getAttribute, getAttributes, getAttributeChangedSignal, getChildren, getDescendants, findFirstChild, findFirstChildOfClass, findFirstChildWhichIsA, findFirstAncestor, findFirstAncestorWhichIsA, waitForChild, isA, isDescendantOf, isAncestorOf, getFullName, clearAllChildren, destroy, clone, toString
Events
Section titled “Events”focusLost
Section titled “focusLost”Arguments: enterPressed: boolean
Client: fires when the field loses focus; enterPressed is true when Enter did it.
Inherited from Instance: changed, childAdded, childRemoved, descendantAdded, descendantRemoving, ancestryChanged, destroying, attributeChanged
Examples
Section titled “Examples”Send a name to the server
Section titled “Send a name to the server”import { PlayerGui, RemoteEvent, ReplicatedStorage, ScreenGui, TextBox, task, waitForChild, waitForLocalPlayer,} from '@rally/sdk';
// LocalScripttask.spawn(async () => { const me = await waitForLocalPlayer(); const hud = await waitForChild(await waitForChild(me, 'PlayerGui', PlayerGui), 'HUD', ScreenGui); const box = await waitForChild(hud, 'PetName', TextBox); const setPetName = await waitForChild(ReplicatedStorage, 'SetPetName', RemoteEvent); box.placeholderText = 'Name your pet'; box.focusLost.connect((enterPressed) => { if (enterPressed && box.text.trim()) setPetName.fireServer(box.text.trim()); });});