Skip to content

TextBox

A text field players can type in.

  • Inherits: TextLabel → GuiObject → Instance
  • Creatable: Yes: new TextBox(), or Instance.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.

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

Inherited from Instance: getPropertyChangedSignal, setAttribute, getAttribute, getAttributes, getAttributeChangedSignal, getChildren, getDescendants, findFirstChild, findFirstChildOfClass, findFirstChildWhichIsA, findFirstAncestor, findFirstAncestorWhichIsA, waitForChild, isA, isDescendantOf, isAncestorOf, getFullName, clearAllChildren, destroy, clone, toString

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

import {
PlayerGui,
RemoteEvent,
ReplicatedStorage,
ScreenGui,
TextBox,
task,
waitForChild,
waitForLocalPlayer,
} from '@rally/sdk';
// LocalScript
task.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());
});
});