How would I add spaces to each string

Hello, I am looking for a way to add spaces after each strings last letter, right now this is my code.

	game.Players.LocalPlayer.Chatted:Connect(function(msg)
		for i,v in pairs(game.Players:GetPlayers()) do
		for i,c in pairs(workspace.Food:GetChildren()) do
			if game.Players.LocalPlayer:GetRankInGroup(6546779) >= 254 then
				if msg == ";give" .. c.Name .. v.Name then 
					game.ReplicatedStorage.RemoteEvent:FireServer(c, v)
			       end
			   end
		end
		end
	end)

Now when you say ;giveBurgerMahooy22022 that works, so what i am looking to do is make it so when you say ;give Burger Mahooy22022 that works instead of no spaces.

1 Like

This script have big problem, exploiter can just call the event
with

game.ReplicatedStorage.RemoteEvent:FireServer("Burger", "NameOfThePlayerUsingThisCode")

there is 2 problem in it, 1 the customer can directly choose the food, 2 he can directly choose the player

Try using a BindableEvent

This is easy to fix, you can add extra spaces:

if msg == ";give ".. c.Name .." ".. v.Name then

I hope this helps you.

1 Like

You can do msg:split(" ") then it splits the message with words.

Example:
“;give Burger uhi_o”

local SplittedMessage = msg:split(" ") --Returns a table
local Item = SplittedMessage[2] --Burger
local User = SplittedMessage[3] --uhi_o

If you want to check the prefix you can do this

local SplittedMessage = msg:split(" ") --Returns a table
local CMD = SplittedMessage:split(";") --Table looking like this {";", "Burger"}
local Item = CMD[2] --Burger
local User = SplittedMessage[3] --uhi_o

Or you can also do what @Conejin_Alt said. I just complicated things without realizing I can do that.

1 Like

Just remove all spaces from the message before you check: I would not recommend @Conejin_Alt’s approach since it will not work if the player accidentally adds an extra space.

-- add right before the if msg == ";give" .. c.Name .. v.Name then
msg = string.gsub(msg, " ","")  

Also, ensure you check the player’s rank on the server before you execute the command. You could also move this system to the server by getting the player from the PlayerAdded event btw.

You can do if msg == ";give" .. " " .. c.Name .. " " .. v.Name then.

See if that works.

I know it’s been almost 4 years since this was posted, but you can simply add a space after the “;give”, like ";give " .. c.Name .. v.Name