Hello. I am trying to write a piece of code that allows a player to edit their overhead gui. This particular function concerns the player's ability to toggle on/off the name.
On line 6, there may be an error if the user has not yet entered a name. If they have not, an error shows if they try to toggle their name back on. "(string expected, got nil)"
Obviously, I tried to rectify that on the next elseif statement, but the program stops reading at the error.
Is there any way to get past this?
remote.OnServerEvent:Connect(function(Player)
if comClone.Data.Text == nameEntered or comClone.Data.Text == Player.Name then
comClone.Data.Text = ""
elseif comClone.Data.Text == "" then
comClone.Data.Text = nameEntered
elseif nameEntered == nil then
comClone.Data.Text = Player.Name
end
end)

3 comments
You're using nameEntered in the second clause, even though you know it can be nil (since you're checking for this in the 3rd clause). Why not reverse the order of those checks?
TextLabels also have a Visible property you can use to hide them, though this might not be an option if you are using something like a UIListLayout, where the layout would change.
Thanks, I will check both of these out.