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
Hey JeffTheEpicRobloxian!
This is a good question, and I hope I can help you with your problem. From what I can tell by your code, you are not letting the Check
function fully traverse or iterate.
Below is an example of what your code should look like...
function Check(Plr) for _, Permitted_Player in pairs(Permitted_Players) do if Plr.Name == Permitted_Player then return true end end return false end
Hope this helps!