How Come One Of My Conditionals Never Runs In My Chat Command Script?
Asked by
4 years ago Edited 4 years ago
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
01 | local Valid_Commands_Table = require(game:GetService( "ServerStorage" ).ValidCommands) |
02 | local Permitted_Players = require(game:GetService( "ServerStorage" ).PlayerNamesPermitted) |
03 | local ToWarnEvent = game:GetService( "ReplicatedStorage" ).ToWarn |
04 | local Maximum_Amount_Of_Warns = 3 |
06 | for _, Permitted_Player in pairs (Permitted_Players) do |
07 | if Plr.Name = = Permitted_Player then |
14 | game:GetService( "Players" ).PlayerAdded:Connect( function (Player) |
15 | local Warns_Num_Value = Instance.new( "NumberValue" ) |
16 | Warns_Num_Value .Parent = Player |
17 | Warns_Num_Value.Name = "Warns" |
18 | Player.Chatted:Connect( function (StringMsg) |
19 | local SplitString = StringMsg:split( " " ) |
20 | if Check(Player) and SplitString [ 1 ] = = Valid_Commands_Table [ 1 ] then |
21 | local NameOfPlayer = SplitString [ 2 ] |
22 | local ActualPlayer = game:GetService( "Players" ):FindFirstChild(NameOfPlayer) |
24 | local Reason = StringMsg:split(NameOfPlayer) [ 2 ] |
25 | ActualPlayer:Kick(Reason) |
27 | elseif Check(Player) and SplitString [ 1 ] = = Valid_Commands_Table [ 2 ] then |
28 | local Name_Of_Player = SplitString [ 2 ] |
29 | local PlayerToWarn = game:GetService( "Players" ):FindFirstChild(Name_Of_Player) |
30 | local Reason = StringMsg:split(Name_Of_Player) [ 2 ] |
31 | local WarnsInPlayer = PlayerToWarn:WaitForChild( "Warns" ) |
33 | WarnsInPlayer.Value + = 1 |
34 | ToWarnEvent:FireClient(PlayerToWarn) |
35 | if WarnsInPlayer.Value > = 3 then |
36 | PlayerToWarn:Kick( "Max Number Of Warns Reached, therefore you have been kicked from the server." ) |
39 | elseif Check(Player) and SplitString [ 1 ] = = Valid_Commands_Table [ 3 ] then |
40 | local Targets = SplitString [ 2 ] |
41 | if Targets = = "All" then |
42 | for _, TargetedPlayer in pairs (game:GetService( "Players" ):GetChildren()) do |
43 | local Char_Of_Plr = TargetedPlayer.Character |
44 | local HumanoidOfTP = Char_Of_Plr.Humanoid |
45 | HumanoidOfTP:TakeDamage(HumanoidOfTP.MaxHealth) |
48 | local NameOfTargetedPlr = SplitString [ 2 ] |
49 | local ActualPlayer = game:GetService( "Players" ):FindFirstChild(NameOfTargetedPlr) |
51 | ActualPlayer.Character.Humanoid:TakeDamage(ActualPlayer.Character.Humanoid.MaxHealth) |
54 | elseif Check(Player) and SplitString [ 1 ] = = Valid_Commands_Table [ 4 ] then |
55 | local Target = SplitString [ 2 ] |
56 | if not Target = = "All" then |
57 | local NameOfPlr = SplitString [ 2 ] |
58 | local ActualPlayer = game:GetService( "Players" ):FindFirstChild(NameOfPlr) |
60 | ActualPlayer.Character:WaitForChild( "Humanoid" ).WalkSpeed = tonumber (StringMsg:split(NameOfPlr) [ 2 ] ) |
62 | elseif Target = = "All" then |
63 | for _, plr in pairs (game:GetService( "Players" ):GetChildren()) do |
64 | plr.Character.Humanoid.WalkSpeed = tonumber (StringMsg:split(Target) [ 2 ] ) |
Part That Doesn't Run
1 | local Target = SplitString [ 2 ] |
2 | if not Target = = "All" then |
3 | local NameOfPlr = SplitString [ 2 ] |
4 | local ActualPlayer = game:GetService( "Players" ):FindFirstChild(NameOfPlr) |
6 | ActualPlayer.Character:WaitForChild( "Humanoid" ).WalkSpeed = tonumber (StringMsg:split(NameOfPlr) [ 2 ] ) |