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

How do I correct this string.sub() problem?

Asked by 5 years ago

So to keep it short I have a script that does some string manipulation to get a player's name. Firsly it detects if you typed "kick" and then it string.sub's it out to only get the player and then check if the player exists. So if I type "kick koreact" it will look for "koreact" in the players list and then kick him. The problem is I want to add a extra message to it. So Instead of that I want it too look like so: kick koreact abusing your powers I don't know how I would go about removing "kick koreact " from the string and only keeping "abusing your powers" in it..

msg is what you wrote such as "kick playername messagehere"

search is "local search = string.sub(msg,6)" (remove "kick " from the string)

Here's the code:

if string.sub(msg,1,4) == "kick" then
local search = string.sub(msg,6)
local len = string.len(search)
for i,v in pairs(game.Players:GetChildren()) do
local namelen = string.len(tostring(v))     
if string.sub(tostring(v),1,len) == search then 
local PlayerToKick = tostring(v)
game.Workspace:WaitForChild("ConsoleManagement").Kick:FireServer(PlayerToKick)
end
end
end
1
possibly using gmatch instead of sub theking48989987 2147 — 5y

Answer this question