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

How Do I Make The Chat Service Do This Command?

How or What is the script that does something when you talk...

for example if i say in roblox chat, :give me gun,

what script will i use that recognises that

and then i will make it give a gun whenever someone says it

pls help

3 comments

0

someone

0

SIMPLE! I know the fix only I know it. He he he he heh

0

Whats that supposed to mean?

2 answers

You can use the game.Players.PlayerAdded event and the player.Chatted event. We can use string patterns to split our message up into arguments to make them easy to work with. We use a table of commands for this.

-- This is the first character we want to check messages for.
local AdminSignalCharacter = ":"

local Weapons = game.ServerStorage.Weapons

-- AdminCommands is a table that maps strings to functions. The string is the command name, the function is that of the command to be executed.
local AdminCommands = {
	give = function(Player, WeaponName)
		if not Weapons:FindFirstChild(WeaponName) then
			return
		end

		local WeaponClone = Weapon[WeaponName]:Clone()
		WeaponClone.Parent = Player:WaitForChild("Backpack")
	end
}

game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		if Message:sub(1, 1) ~= AdminSignalCharacter then
			return
		end

		-- Get the substring not including the signal character.
		local CommandMessage = Message:sub(2)

		local Command = nil
		local Arguments = {}

		-- Match one or more word characters in a generic for loop.
		for Match in CommandMessage:gmatch("%w+") do
			if Command then
				-- We already know what command we're using, so it's an argument to it.
				table.insert(Arguments, Match)
			else
				-- If we don't already know the command, this must be the first match.
				Command = Match:lower()
			end
		end

		-- If there were no matches.
		if not Command then
			return
		end

		local CommandExecutor = AdminCommands[Command]

		-- If the command doesn't exist.
		if not CommandExecutor then
			return
		end

		-- Call the function in AdminCommands.
		CommandExecutor(Player, unpack(Arguments))
	end)
end)

20 comments

0

You'd say :give [weaponNameHere] where weaponNameHere would be the name of the weapon to clone.

0

The code I posted would go in as a Script in game.ServerScriptService.

0

Why do you keep unaccepting my answer? And yes, Weapons is a folder.

0

I'm pointing it to a folder of weapons. It can clone any weapon in that folder. I don't know why you keep unaccepting my answer over and over again every 2 seconds, I already answered your question.

0

Yes, but call it IDCard with no spaces and you'd type :give IDCard

0

I made a typo, it should be Weapons not Weapon.

0

No you don't need to change that part in the script.

0

Yeah, I made another typo. I fixed it in the answer. Remove the () from WeaponClone().Parent.

0

BUT how can i make it so i can also type in the player name so i can give it to someone else PLSSSSS is it possible if yes please answer plssss

0

Add another argument to the function.

0

This is Scripting Helpers, I gave you a massive chunk of the code, you should be trying to do it yourself, this isn't a request site.

0

pls genius guy i love u

0

I recommend checking this Wiki article to learn how to add another parameter: http://wiki.roblox.com/index.php?title=Function and you'd find the player through a string, and give it to them.

0

It's not a final chance or final script thing, I'm not trying to punish you or anything here, but begging in all caps isn't going to do anything. This is a site for help with scripting, not a request site. If you have no interest in doing something like this yourself, it might not be the right place to ask your questions.

0

I DO WANT TO SIR BUT I JUST WANT U TO DO IT FIRST THEN I WILL LEARN PEOPLE LIKE ME LEARN IN THIS WAY ITS BEST WAY OF LEARNING FOR ME BECUASE ONCE U DONE IT THEN I WILL ALSO BE ABLE TO DO IT PLSS

0

Do it yourself.

0

plsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss sir plssssssssssssssssssssssssssssssssssssssss

0

Sorry, need to go. Nobody else is likely to make this script for you either, you'll need to base it off the geneorous amount of code I posted.

0

lol u pride urself but u didnt help me :(

0

You're spoiled. Leave this site, you don't belong here.

So i pass in the argument like this

give = function(Player, WeaponName, playerName)

now what?

i know a string is like this

playerName = game.Players.LocalPlayer.Name

But tell me how i can fit it in

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