how do i stop players from renaming textboxes?
how do i stop players from renaming textboxes?
3 answers
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
yeah but ur using character ' ' so....
That is probably the stupidest thing I've ever seen.
True, though I did necessarily go a tad in depth then posting code, so I kinda still count
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.
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
smh u copy'd shaskerlol
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
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.
He asked for the name not the text lol
This discussion is preserved as it was. New answers, comments, and votes are closed.

12 comments
They can't to begin with
they can do end with
? Explain your issue throughly so we can be better-equipped at helping you.
wait or is it like only in roblox studio that you can rename the
You can only set the Name of an Object in Studio, unless you specifically have Code taking Input and setting it accordingly.
:o ok then just post an answer ill accept xd
I was already making one from the start;)
actually i think i know what you mean, ill work something out in a sec
I answered your question. Accept if it helped.
lol what is wrong with single quotes
Use textlabel?
I figured out the best method available for this, you can check my answer now