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

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

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 comment

1

PLEASE indent your code!

1 answer

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.

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