How could I make a :walkspeed command?

I want to make a chat command. For example, a player types “:walkspeed (playername) (speed)”.I’ve tried experimenting, but I don’t really get it.

1 Like

Either attempt to make a script that we can help you fix or hire someone, but:

1 Like

This is what I’ve tried.

elseif Msg:sub(1,11) == Prefix.."walkspeed "..Player.Name then
				local Target = Players:FindFirstChild(Msg:sub(13))
				local Valid = CheckForTarget(Target)
				
				if Valid then
					local Playerlength = Players:WaitForChild(Msg:sub(12)).length()
						Players.Character.Humanoid.WalkSpeed = Msg:sub(1,11+Playerlength.." ")
					end
1 Like

Hmm, yeah, without a full script this is very hard to read. Also, you need to make sure the command has three parts:

  • prefix
  • char searcher
  • speed input

You could try this

  if message == 'walkspeed add' and player.Character then
  	player.Character.Humanoid.WalkSpeed = player.Character.Humanoid.WalkSpeed + 100
  end
end
local function onPlayerAdded(player)
  player.Chatted:Connect(function (message) onPlayerChatted(player, message) end)
end
game.Players.PlayerAdded:Connect(onPlayerAdded)

I don’t want to add to it, I want to set it.

Hmm, so the Msg:sub(1,11) == Prefix.."walkspeed "..Player.Name is case + space sentitive. Also, a players name can be very long like mine. If you only check the first through the 11th character, this is what the code would check in my username:
" !walkspeed " so maybe remove the Player.Name part and put it in another code, like
if game.Players:FindFirstChild(Msg:sub(12,#Msg)) then under elseif Msg:sub(1,11) == Prefix.."walkspeed " It could work?(Sorry if this is messy, this is my first reply)

1 Like

This worked in studio for me,

	local function convert(s)
		s = string.gsub(s, "walkspeed ", "")
		return tonumber(s)
	end

	local amount = convert(message)
	if message == "walkspeed "..amount and player.Character then
		player.Character.Humanoid.WalkSpeed = amount
	end
end
local function onPlayerAdded(player)
	player.Chatted:Connect(function (message) onPlayerChatted(player, message) end)
end
game.Players.PlayerAdded:Connect(onPlayerAdded)

Just say "walkspeeed " then the number you want to set it to.

You did a recent post about “ff and uff commands” please use the format that the other guy and I made.

Oh sorry, the wrong quote, I’m saying because the Author of the post already made a post about commands, and the other guy and I helped on this, he could just use the format of the last post.

No, I did a wrong quote, sorry.

1 Like

I’m going to do the same thing of your other post about others commands…

game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		if Player.Name == "ADMIN NAME HERE" then

			local Arguments = string.split(Message, " ")

			if Arguments[1] == ":walkspeed" then
				local Target = Arguments[2]

				if game.Players:FindFirstChild(Arguments[2]) then
					local TarCharacter = Target.Character
					
					local SpeedToChange = tonumber(Argument[3])

					if SpeedToChange then
						if TarCharacter:FindFirstChild("Humanoid") then
							TagCharacter.Humanoid.WalkSpeed = Argument[3]
						end
					else
						return false; --> The Argument 3 may not be a number or does not exist.
					end
				else
					return false; --> The Player does not exist or is not In-Game.
				end
			end
			
		else
			return false; --> Player is not an Administrator.
		end
	end

Updated version:

local prefix = "!"

local function onPlayerChatted(player, message)
	local function convert(s)
		s = string.gsub(s, prefix.."walkspeed ", "")
		return tonumber(s)
	end

	local amount = convert(message)
	if player.UserId == --[[Change the numbers to the right of this to your roblox id]]340621144 then
	    if message == prefix.."walkspeed "..amount and player.Character then
		   player.Character.Humanoid.WalkSpeed = amount
		end
	end
end
local function onPlayerAdded(player)
	player.Chatted:Connect(function (message) onPlayerChatted(player, message) end)
end
game.Players.PlayerAdded:Connect(onPlayerAdded)

There is a more efficient way to this and that is using string patterns and string.match() function. Here is an example:

game.Players.LocalPlayer.Chatted:Connect(function(message)
	local Player, Walkspeed = string.match(message, "^%s*:walkspeed%s+(.+)%s+(%d+)%s*$") --Captures string for player name and walkspeed number.
	if Player ~= nil and game.Players:FindFirstChild(Player) ~= nil and Walkspeed ~= nil then --Checks if player exist and walkspeed parameter is specified.
		game.Players:FindFirstChild(Player).Character.Humanoid.WalkSpeed = Walkspeed
	end
end)

Yes but you can’t do a walkspeed command on a localscript

I know. I just gave an example, nothing more. It’s up to the owner of this post to use the info I gave him/her properly.

1 Like

Hello there! I’ve created a version of my own utilizing different Developer API’s, I know other people have already posted possible solutions but here is my own version which you can extract the logic from! This method comes with a table which you can expand to multiple users who want to use the command. This script can be placed in a Server Script inside of ServerScriptService.

The script currently runs in the form of what you stated:
Ex: (:walkspeed HelloPlayer123 20)

local Players = game:GetService("Players") -- Get Player Service

--List of players in a table, to add more players add ["UserNameHere"] = true, to another line in the table
local playerlist = {
	["PlayerName1"] = true,
	["PlayerName2"] = true,
	["PlayerName3"] = true,
	["EtcUsers..."] = true,	
}
local CommandName = ":walkspeed" -- Command Name String

local function runCommand(player, message)
	local values = tostring(message):split(" ") -- Splits chat message by spaces (" ") into a table by (message, playername, speedvalue)
	local command = tostring(values[1]) -- Command Name in Table
	
	if command:lower() == CommandName:lower() then -- Checks the Command in the Table
		local name = tostring(values[2]) -- Requested Name in table
		local speed = tonumber(values[3]) -- Speed Value in Table
		local playerToSpeed = Players:FindFirstChild(name) -- Gets the player
		if playerToSpeed and speed ~= nil then -- Checks to see if there is a player, and if there is a speed value
			playerToSpeed.Character:WaitForChild("Humanoid").WalkSpeed = speed -- Changes the requested players speed
		else
			-- Error In Question
		end
	end
end

local function onPlayerAdded(player)
	-- Restrict this command to only users in the table
	if playerlist[player.Name] then
		player.Chatted:Connect(function (...)
			runCommand(player, ...)
		end)
	end
end

-- Listen for players being added
for _, player in pairs(Players:GetPlayers()) do
	onPlayerAdded(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)
5 Likes