Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[Solved]Will string.match(msg, "%d+") always return the first number it finds?

Asked by 5 years ago
Edited 5 years ago

I want to make sure that this admin script will not cause errors when more than one number is entered. Here is the script:

            local humanoid = player.Character.Humanoid

            if string.lower(string.sub(msg, 1, 5)) == "speed" then

                local strPlayerSpeed = string.match(msg, "%d+")             

                if strPlayerSpeed then

                    local numPlayerSpeed = tonumber(strPlayerSpeed)

                    if numPlayerSpeed <= 256 then

                        humanoid.WalkSpeed = numPlayerSpeed

                    end
                end

My second question is what does % do in string.find and string.match local slashIndex = string.find(msg, "%/") is this the way it should be used? Also lets say I want to find a letter do I really need to use %? please tell me what it is for. Thanks!

0
As a note, this will not catch the whole number if it is a negative and/or not an integer. hiimgoodpack 2009 — 5y

Answer this question