I'm making Chat Commands and recently I've added a new one. This Command is meant to speed up the targeted player by adjusting the walk speed of the humanoid. However, although the Speed All Part works, targeting a specific player (via name) never does. To Be Able To Convert the string to an actual number, I use the tonumber() method. Help Appreciated!
Edit: I updated the script to what I currently have
Full Code
local Valid_Commands_Table = require(game:GetService("ServerStorage").ValidCommands)
local Permitted_Players = require(game:GetService("ServerStorage").PlayerNamesPermitted)
local ToWarnEvent = game:GetService("ReplicatedStorage").ToWarn
local Maximum_Amount_Of_Warns = 3
function Check(Plr)
for _, Permitted_Player in pairs(Permitted_Players) do
if Plr.Name == Permitted_Player then
return true
else
return false
end
end
end
game:GetService("Players").PlayerAdded:Connect(function(Player)
local Warns_Num_Value = Instance.new("NumberValue")
Warns_Num_Value .Parent = Player
Warns_Num_Value.Name = "Warns"
Player.Chatted:Connect(function(StringMsg)
local SplitString = StringMsg:split(" ")
if Check(Player) and SplitString[1] == Valid_Commands_Table[1] then --Kick Command
local NameOfPlayer = SplitString[2]
local ActualPlayer = game:GetService("Players"):FindFirstChild(NameOfPlayer)
if ActualPlayer then
local Reason = StringMsg:split(NameOfPlayer)[2]
ActualPlayer:Kick(Reason)
end
elseif Check(Player) and SplitString[1] == Valid_Commands_Table[2] then
local Name_Of_Player = SplitString[2]
local PlayerToWarn = game:GetService("Players"):FindFirstChild(Name_Of_Player)
local Reason = StringMsg:split(Name_Of_Player)[2]
local WarnsInPlayer = PlayerToWarn:WaitForChild("Warns")
if WarnsInPlayer then
WarnsInPlayer.Value += 1
ToWarnEvent:FireClient(PlayerToWarn)
if WarnsInPlayer.Value >= 3 then
PlayerToWarn:Kick("Max Number Of Warns Reached, therefore you have been kicked from the server.")
end
end
elseif Check(Player) and SplitString[1] == Valid_Commands_Table[3] then
local Targets = SplitString[2]
if Targets == "All" then
for _, TargetedPlayer in pairs(game:GetService("Players"):GetChildren()) do
local Char_Of_Plr = TargetedPlayer.Character
local HumanoidOfTP = Char_Of_Plr.Humanoid
HumanoidOfTP:TakeDamage(HumanoidOfTP.MaxHealth)
end
else
local NameOfTargetedPlr = SplitString[2]
local ActualPlayer = game:GetService("Players"):FindFirstChild(NameOfTargetedPlr)
if ActualPlayer then
ActualPlayer.Character.Humanoid:TakeDamage(ActualPlayer.Character.Humanoid.MaxHealth)
end
end
elseif Check(Player) and SplitString[1] == Valid_Commands_Table[4] then
local Target = SplitString[2]
if not Target == "All" then
local NameOfPlr = SplitString[2]
local ActualPlayer = game:GetService("Players"):FindFirstChild(NameOfPlr)
if ActualPlayer then
ActualPlayer.Character:WaitForChild("Humanoid").WalkSpeed = tonumber(StringMsg:split(NameOfPlr)[2])
end
elseif Target == "All" then
for _, plr in pairs(game:GetService("Players"):GetChildren()) do
plr.Character.Humanoid.WalkSpeed = tonumber(StringMsg:split(Target)[2])
end
end
end
end)
end)
Part That Doesn't Run
local Target = SplitString[2]
if not Target == "All" then
local NameOfPlr = SplitString[2]
local ActualPlayer = game:GetService("Players"):FindFirstChild(NameOfPlr)
if ActualPlayer then
ActualPlayer.Character:WaitForChild("Humanoid").WalkSpeed = tonumber(StringMsg:split(NameOfPlr)[2])
end

8 comments
You're not letting the Check function fully evaluate each expression; let it iterate through each "Permitted Player" until** it finds a match.
k so i dont do the return Plr.Name == plrPermitted, but instead make it check if it matches a player, and if it does then i return true?
ill try that
nvrmind it didnt work
Of course it didn't, you're still not letting it traverse. A return statement cancels the scope. Use "return false" outside of the enumeration, that way, the logic states that if no match was found, it'll give a false impression.
Alr
NEVER use PlayerName. It's unsecure and if someone changesa their username it won't work. Use Player.UserId instead
Alr Ill change that then