Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

01local Valid_Commands_Table = require(game:GetService("ServerStorage").ValidCommands)
02local Permitted_Players = require(game:GetService("ServerStorage").PlayerNamesPermitted)
03local ToWarnEvent = game:GetService("ReplicatedStorage").ToWarn
04local Maximum_Amount_Of_Warns = 3
05function Check(Plr)
06    for _, Permitted_Player in pairs(Permitted_Players) do
07        if Plr.Name == Permitted_Player then
08            return true
09        else
10            return false
11        end
12    end
13end
14game:GetService("Players").PlayerAdded:Connect(function(Player)
15    local Warns_Num_Value = Instance.new("NumberValue")
View all 69 lines...

Part That Doesn't Run

1local Target = SplitString[2]
2        if  not Target == "All" then
3            local NameOfPlr = SplitString[2]
4            local ActualPlayer = game:GetService("Players"):FindFirstChild(NameOfPlr)
5            if ActualPlayer then
6                ActualPlayer.Character:WaitForChild("Humanoid").WalkSpeed = tonumber(StringMsg:split(NameOfPlr)[2])
7            end
0
You're not letting the Check function fully evaluate each expression; let it iterate through each "Permitted Player" until** it finds a match. Ziffixture 6913 — 4y
0
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? JeffTheEpicRobloxian 258 — 4y
0
ill try that JeffTheEpicRobloxian 258 — 4y
0
nvrmind it didnt work JeffTheEpicRobloxian 258 — 4y
View all comments (4 more)
0
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. Ziffixture 6913 — 4y
0
Alr JeffTheEpicRobloxian 258 — 4y
0
NEVER use PlayerName. It's unsecure and if someone changesa their username it won't work. Use Player.UserId instead nekosiwifi 398 — 4y
0
Alr Ill change that then JeffTheEpicRobloxian 258 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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...

1function Check(Plr)
2    for _, Permitted_Player in pairs(Permitted_Players) do
3        if Plr.Name == Permitted_Player then
4            return true
5        end
6    end
7    return false
8end

Hope this helps!

0
Thanks! JeffTheEpicRobloxian 258 — 4y
Ad

Answer this question