How do I find numbers in string?

Hello, I am XXgamerisaliveXx, and I’m making a speed command like “/speed me”, my question how do I find if the player typed a number in the command “/speed me”, how would I do that? Please explain if any of you know.

1 Like

just prob do:

game.Players.PlayedAdded:Connect(function(Player)
    Player.Chatted:Connect(function(Chat)
        local Split = Chat:split(" ")
        
        if Split[1] == "/Speed" then
            local SpeedV = Split[2] -- WalkSpeed stuff
            
            if tonumber(SpeedV) then
                print(SpeedV)
            end
        end
    end)
end)
5 Likes

Thanks, let me try! I hope this works.

2 Likes

Wow, this really worked! Thank you!

2 Likes

just prob also do:

game.Players.PlayedAdded:Connect(function(Player) 
   Player.Chatted:Connect(function(msg) -- get the message 
       local n = msg:match("/speed.-(%d+)") -- match "/speed" and at least one occurrence of a number, return the matched number (after going through any character (.) until a number is found)
       print(n or "nope") -- if not nil i.e a match was made, return it  - otherwise return "nope"
   end)
end)

String manipulation can be very helpful at times, specifically pattern matching in this case.

Let me try this, I don’t know much about string manipulation.