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

How do I make a speed command work with my admin script?

Asked by 5 years ago

Hello, so I am making an admin script but I can't seem to understand how to get commands like speed [p] [v] to work. Any help would be fine, thanks.

plr = game.Players.LocalPlayer

prefix = ":"
banned = {}

function GetPlayer(String)
 local Found = {}
 local strl = String:lower()
 if strl == "all" then
     for i,v in pairs(game.Players:GetPlayers()) do
         table.insert(Found,v)
     end
 elseif strl == "others" then
     for i,v in pairs(game.Players:GetPlayers()) do
         if v.Name ~= game.Players.LocalPlayer.Name then
             table.insert(Found,v)
         end
     end   
elseif strl == "me" then
     for i,v in pairs(game.Players:GetPlayers()) do
         if v.Name == game.Players.LocalPlayer.Name then
             table.insert(Found,v)
         end
     end  
 else
     for i,v in pairs(game.Players:GetPlayers()) do
         if v.Name:lower():sub(1, #String) == String:lower() then
             table.insert(Found,v)
         end
     end    
 end
 return Found    
end

plr.Chatted:Connect(function(msg)
if string.sub(msg, 1, 6) == (prefix.."kick ") then
for i,v in pairs(GetPlayer(string.sub(msg, 7))) do
local remote = game.Players.LocalPlayer.Backpack.Delete.delete
remote:FireServer(v)
end
end
end)

plr.Chatted:Connect(function(msg)
if string.sub(msg, 1, 6) == (prefix.."speed ") then
for i,v in pairs(GetPlayer(string.sub(msg, 7))) do
plr.Character.Humanoid.WalkSpeed = (string.sub(msg, 8))
end
end
end)
1
PLEASE indent your code! User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

I just added a new thing to the table called data. The data is the second argument of the command. If there is no second argument, then the data is nil. I also made a local variable for each command called data. So if you need to get the second argument, you just do data.data. You don't need a Connect for each chatted event so I just put it all into one event. Here is the updated code.

plr = game.Players.LocalPlayer

prefix = ":"
banned = {}

function GetPlayer(String)
 local Found = {}
 local strl = String:lower()
if string.find(strl," ") then
    Found.data = string.sub(strl,string.find(strl," ")+1)
end
 if strl == "all" then
     for i,v in pairs(game.Players:GetPlayers()) do
         table.insert(Found,v)
     end
 elseif strl == "others" then
     for i,v in pairs(game.Players:GetPlayers()) do
         if v.Name ~= game.Players.LocalPlayer.Name then
             table.insert(Found,v)
         end
     end   
elseif strl == "me" then
     for i,v in pairs(game.Players:GetPlayers()) do
         if v.Name == game.Players.LocalPlayer.Name then
             table.insert(Found,v)
         end
     end  
 else
     for i,v in pairs(game.Players:GetPlayers()) do
         if v.Name:lower():sub(1, #String) == String:lower() then
             table.insert(Found,v)
         end
     end    
 end
 return Found    
end

plr.Chatted:Connect(function(msg)
    if string.sub(msg, 1, 6) == (prefix.."kick ") then
    local data = GetPlayer(string.sub(msg, 7))
        for i,v in pairs(data) do
        local remote = game.Players.LocalPlayer.Backpack.Delete.delete
        remote:FireServer(v)
        end
    end
    if string.sub(msg, 1, 7) == (prefix.."speed ") then
    local data = GetPlayer(string.sub(msg, 8))
        for i,v in pairs(data) do
        plr.Character.Humanoid.WalkSpeed = data.data
        end
    end
end)

Since I've made my own admin script before, I have some experience in this.

Ad

Answer this question