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

heelp I need to add a prefix?

local player = game.Players.LocalPlayer
local prefix = "."
player.Chatted:Connect(function(msg)
    local target 
    if msg:lower():match("goto") then
        if game.Players:FindFirstChild(msg:sub(6)) then
            target = workspace:FindFirstChild(msg:sub(6))
            print(target)
            player.Character.HumanoidRootPart.CFrame = CFrame.new(target.Head.Position)
        end
    end
end)

1 comment

0

Don't call FindFirstChild twice, that's inefficient. Store the return result in a variable, check the result, then use the variable.

1 answer

You need to expand on your string pattern.

The prefix you wish to use is considered a "magic character", so you will need to escape the dot to ensure it is evaluated literally. This is done with the % character. Furthermore, you can use string captures to eliminate the need for string:sub.

-- "^" ensures the pattern occurs at the beginning of the string. See the 
-- hyperlink to get a better understanding of the full pattern.

local Arguments = (".goto Ziffixture"):match("^%.goto (.+)")
if Arguments then
	print(Arguments) --> "Ziffixture" (Match was successful)
end

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