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

how do i stop players from renaming textboxes?

how do i stop players from renaming textboxes?

12 comments

0

They can't to begin with

0

they can do end with

0

? Explain your issue throughly so we can be better-equipped at helping you.

0

wait or is it like only in roblox studio that you can rename the

0

You can only set the Name of an Object in Studio, unless you specifically have Code taking Input and setting it accordingly.

0

:o ok then just post an answer ill accept xd

0

I was already making one from the start;)

0

actually i think i know what you mean, ill work something out in a sec

0

I answered your question. Accept if it helped.

0

lol what is wrong with single quotes

0

Use textlabel?

0

I figured out the best method available for this, you can check my answer now

3 answers

✓ Accepted answer
local DEFAULT_NAME = script.Parent.Name

script.Parent:GetPropertyChangedSignal('Name'):Connect(function()
    script.Parent.Name = DEFAULT_NAME
end)

Local Script in your TextButton

When name changes reset it back

5 comments

0

yeah but ur using character ' ' so....

0

That is probably the stupidest thing I've ever seen.

0

True, though I did necessarily go a tad in depth then posting code, so I kinda still count

0

But, but but but you are talking about going through the properties manually which other player's can't do. I find it messed up you get credit for taking his codes so I will accept this answer. Also an essay on how this works is redundant. "When name changes reset it back" is the easiest it gets.

0

fair deal

Generally, I don’t understand the Question you’ve asked, but I will assume you’re regarding to the Studio and ability to rename Objects.


Quick answer, there is no way to prevent it as it’s exclusively made to be able to do so, the Studio is there for making the Game. In-game, you cannot access these Objects’ properties so ultimately the Player wouldn’t be able to change them at all. That is unless you’ve written a Script with the task of taking Input from an InputField and renaming the referenced Object accordingly.


If you truly desire to prevent the change of a Name, you can use a Listener for the Object’s changed Name property and set it back

--// Child if the GuiObject | credit to ShAskerlol - basic concept, all I had too.
local OriginalName = script.Parent.Name

script.Parent:GetPropertyChangedSignal("Name"):Connect(function()
   script.Parent.Name = OriginalName
end)

Though this would only work when playing the Game.

2 comments

0

smh u copy'd shaskerlol

0

It is generally the only solution, I ended up writing the same thing

EDIT: Better Method

Option 3: Use :GetPropertyChangedSignal()

local textbox = script.Parent:WaitForChild("TextBox")
local prevent = false
local finaltext = ""

game:GetService("UserInputService").InputBegan:Connect(function(input)
	if (input.UserInputType == Enum.UserInputType.MouseButton1 or input.KeyCode == Enum.KeyCode.Return) and textbox.Text ~= "" then
		textbox:ReleaseFocus(false)
		textbox.ClearTextOnFocus = false
		prevent = true
		finaltext = textbox.Text
	end
end)

textbox:GetPropertyChangedSignal("Text"):Connect(function()
	if prevent == true then
		textbox = finaltext
	end
end)

Reasons for each part of this code are outlined below

ORIGINAL POST

Ok, so I went through the TextBox Properties, there is a property named ClearTextOnFocus which you can make false so that the text stays how it is.

However, the player can still add to the text in the TextBox, which is why i suggest having a back-up TextLabel to switch into. There are two ways to do this:

Local Script (Long Version)

local textbox = script.Parent:WaitForChild("TextBox")

textbox.FocusLost:Connect(function(bool, input)
	local textlabel = Instance.new("TextLabel")
	textlabel.Active = textbox.Active
	textlabel.AnchorPoint = textbox.AnchorPoint
	textlabel.BackgroundColor3 = textbox.BackgroundColor3
	textlabel.BackgroundTransparency = textbox.BackgroundTransparency
	textlabel.BorderColor3 = textbox.BorderColor3
	textlabel.BorderSizePixel = textbox.BorderSizePixel
	textlabel.LayoutOrder = textbox.LayoutOrder
	textlabel.Position = textbox.Position
	textlabel.Rotation = textlabel.Rotation
	textlabel.Selectable = false
	textlabel.Size = textbox.Size
	textlabel.SizeConstraint = textbox.SizeConstraint
	textlabel.ZIndex = textbox.ZIndex
	textlabel.Archivable = true
	textlabel.ClipsDescendants = textbox.ClipsDescendants
	textlabel.NextSelectionDown = textbox.NextSelectionDown
	textlabel.NextSelectionLeft = textbox.NextSelectionLeft
	textlabel.NextSelectionRight = textbox.NextSelectionRight
	textlabel.NextSelectionUp = textbox.NextSelectionUp
	textlabel.Font = textbox.Font
	textlabel.Text = textbox.Text
	textlabel.TextColor3 = textbox.TextColor3
	textlabel.TextStrokeTransparency = textbox.TextStrokeTransparency
	textlabel.TextTransparency = textbox.TextTransparency
	textlabel.TextScaled = textbox.TextScaled
	textlabel.TextTruncate = textbox.TextTruncate
	textlabel.TextWrapped = textbox.TextWrapped
	textlabel.TextXAlignment = textbox.TextXAlignment
	textlabel.TextYAlignment = textbox.TextYAlignment
	textlabel.AutoLocalize = true
	textlabel.Parent = textbox.Parent
	textbox.Visible = false
end)

game:GetService("UserInputService").InputBegan:Connect(function(input)
	if (input.UserInputType == Enum.UserInputType.MouseButton1 or input.KeyCode == Enum.KeyCode.Return) and textbox.Text ~= "" then
		textbox:ReleaseFocus(false)
	end
end)

Local Script (Short Version)

local textbox = script.Parent:WaitForChild("TextBox")
local textlabel = script.Parent:WaitForChild("TextLabel")

textbox.FocusLost:Connect(function(bool, input)
	local textlabel = Instance.new("TextLabel")
	textlabel.Text = textbox.Text
	textbox.Visible = false
end)

game:GetService("UserInputService").InputBegan:Connect(function(input)
	if (input.UserInputType == Enum.UserInputType.MouseButton1 or input.KeyCode == Enum.KeyCode.Return) and textbox.Text ~= "" then
		textbox:ReleaseFocus(false)
	end
end)

The long version means you manually change all the values when you create the label

The short version means you change the label properties to match those of the textbox and place it under the textbox parent as well.

The event/function you will require for this are the TextBox.FocusLost which fires when the textbox cursor is removed, and the TextBox:ReleaseFocus() Function which will automatically release the cursor

In order to activate the release, we check that the textbox's text is no longer empty (make sure that the ClearTextOnFocus is set to true) and check that either the mouse was clicked or the return key was pressed.

2 comments

0

Whichever Moderator just made a Note on this answer, read the question again, this does answer how to prevent players from continuing to change the textbox text, since logically they cant change the textbox's actual name unless it was scripted to be able do so.

0

He asked for the name not the text lol

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