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.
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.
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.