How would i do this?

Im making a admin commands script.
How would i check if a player is in the game, then change their walkspeed to 50?

Players:GetPlayerByUserId() should be what is needed, if you have the UserId, you can chuck it into the method, and if they’re ingame, it’ll return the player instance, and if they aren’t, it returns nil

You can use the Player.Chatted event which returns the message they sent, you can split the string via spaces using string.split(msg, " "), where msg is the message sent, and check if certain parts have the command, name/userid of a player and the arguments of the command

2 Likes

You detect when player joins with the game.Players.PlayerAdded event and change their walkspeed every time they spawn with player.CharacterAdded and Character.Humanoid.WalkSpeed = 50

I think they understood you not right. Here you go:

Put script in ServerScriptServer and put inside of it:

game.Players.PlayerAdded:Connect(function(plr)
	local admins = {"iShouldG0", "R0mAAn1CH"} --You can erase my name with comma if you want.
	
	if table.find(admins, plr.Name) then
		plr.Chatted:Connect(function(msg)
			if string.match(msg, ":speed ") then
				for i,v in pairs(game.Players:GetChildren()) do
					if string.match(msg, v.Name) then
						local speed = string.gsub(msg, ":speed ", "")
						speed = string.gsub(speed, v.Name.." ", "")
						speed = tonumber(speed)
						
						v.Character.Humanoid.WalkSpeed = speed
						
						print("Gave "..v.Name.." speed "..speed)
						
						break
					end
				end
			elseif string.match(msg, ":jumppower ") then
				for i,v in pairs(game.Players:GetChildren()) do
					if string.match(msg, v.Name) then
						local jm = string.gsub(msg, ":jumppower ", "")
						jm = string.gsub(jm, v.Name.." ", "")
						jm = tonumber(jm)

						v.Character.Humanoid.JumpPower = jm

						print("Gave "..v.Name.." jump power "..jm)

						break
					end
				end
			end
		end)
	end
end)