Change Part SurfaceGUI Text with Custom Command

Scripting commands to change text on a surface GUI

Have you ever wondered how to make your own commands? Maybe to do a specific task? Something that is rank locked and safe from abuse? Well, today, I will be showing, step by step, how to be able to script such a thing!

Creating the Part

  1. First, you must create the part. This is where the surface GUI will be placed. Make sure it is correctly scaled and ready.

  2. Once you have created the part, you must add the surface GUI and a text label with it. Set the surface GUI so it faces correctly and that the text label can be seen.

It should be in the properties of the surface GUI.

  1. Add the “TextLabel” into the surface GUI. It should pop up on your part!

  2. Edit the textlabel so that it fits your entire part. To make sure it is sized correctly, go to your properties tab and select the textlabel. Scroll down to “Size” and change it to {1,0} {1,0}. This is the size that will fit your entire part.

Set the textlabel transparency to 1. Then scroll down and select “Scaled” in the text settings. You can change the text to whatever you would like.

Now, you are done! You have finished the part section! Lets move on to the scripting section.

Here is an example of what your part should look like at the moment:

DA0A6093-F953-436E-ACF2-1D5D8BD2B223_4_5005_c

Scripting

We are going to be using the “ServerScriptService” section today. That is all you will need to use to make the script.

  1. Add a script and add the following code:

5166A671-AE05-4A87-B925-7848A5220EF0_4_5005_c

This will define our group ID for which will check if the player is in the group. If the player is not in the group, the command which they want to use won’t function.

  1. Next, we need to begin the code. We need to check if the player is in the correct rank to be able to use the command. We need to create a function.

C18C9314-348C-4386-BFB9-F90F39A432E4_4_5005_c

The code will check if the player is in the correct rank and see if the player can use the command. Change “255” to the group rank number. If you don’t know how to find this number, go to your group, click configure group, click “Roles”, then copy and paste the role number into the code.

  1. Next step is to tell the script what command to look for.

Continue editing your code to make it look like this:

D8B8C913-BD64-4A16-840F-E2E12713A916_4_5005_c

  1. Now that we have defined the command, the script will look for it when the player says it. But now we need to add the remaining code to tell it what to do when it hears the command.

You can change this section to whatever you like.

Edit your code to make it look like this or similar:

  1. Now that it knows what to do when the player says it, we need to make sure the script stops anyone who isn’t in the group or who isn’t allowed to use the command. We will add an else statement and return the command.

Edit your code to make it look like this or similar:

  1. We are done! Now that we have finished, you can test this out! You can continue to copy and paste your code in the same script to add more ranks that can use this command!

Finishing Touch and Review

Here is the final code for our script!


local groupID = 123456

game.Players.PlayerAdded:Connect(function(Player)
	if Player:GetRankInGroup(groupID) == 255 then
		
		Player.Chatted:Connect(function(message)
			if message == "?command" then
				game.Workspace.TextPart.SurfaceGui.OnPartText.Text = "This is new"
			else
				return message
			end
		end)
	end
end)

Hit the comments below if you guys have any questions or concerns related to this! :slight_smile:

3 Likes

Question: Dose this even filter the message?

This code can’t filter the message as I think moderators and/or people you trust wouldn’t do such thing. There is a way to import a filter. Read the following article: