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

Whitelist System does not detect whitelisted names. How to fix?

Asked by 5 years ago

Basically, I am trying to create a whitelist system for which when the script detects that there is a whitelisted user the user is able to use the speed agility,

if game.Players.LocalPlayer.Name == {"MyBestFriend","mony111133333"}
then
    game:GetService("UserInputService").InputBegan:connect(function(inputObject,gameProcessedEvent)
        if inputObject.KeyCode == Enum.KeyCode.W then
            game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 60
        end 
    end)    

else
game.Players.LocalPlayer:Kick ("You are NOT whitelisted, Join the Discod Server. Sorry!")
end
0
`:Kick()`can only be run on the server Gey4Jesus69 2705 — 5y
0
whitelist = {[123456789] = true, etc etc} User#24403 69 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

The reason for your code not working was because you are comparing the name (a string) to a table, and since the name is never going to be a table your condition was never met. Adding on to MakeYourEscape's answer:

local whitelist = {
    MyBestFriend = true,
    mony111133333 = true
}

game:GetService("Players").PlayerAdded:Connect(function(client)
    client.CharacterAdded:Connect(function(character)
        if whitelist[client.Name] then
            character:WaitForChild("Humanoid").WalkSpeed = 60
        end
    end)
end)

But instead of looping through an array I use a dictionary. I can then check if their name is in the dictionary. I encourage you use the UserId, since you can change your username, but not your UserId. And I don't use UserInputService since you don't need it in this case.


Hopefully this answered your question, and if it did, then don't forget to hit that "Accept Answer" button. If you have any other questions, then feel free to leave them down in the comments.
0
How would the UserId format work? User#25706 0 — 5y
Ad
Log in to vote
-2
Answered by 5 years ago

Well, first, you can only kick users through a server sided script.

I will explain the rest in the code.

--this should be a server script in ServerScriptService

local whitelist = {"MyBestFriend","mony111133333"} --Who is allowed inside.


game.Players.PlayerAdded:Connect(function(plr) --plr being the player, this runs when the player joins the game
    for _,v in pairs(whitelist) do -- this will go through all the items in the whitelist table
        if plr.Name == v then --If the player is found on the whitelist
            workspace:WaitForChild(plr.Name):WaitForChild("Humanoid").WalkSpeed = 60 --sets the player's walk speed to 60
            return "Allowed" -- End everything and let
        else
            wait() --go on to the next item in the list
        end
    end
    plr:Kick("You aren't on the whitelist") -- If the player wasn't found, then the function wouldn't be returned and ended, meaning They aren' on the whitelist!
end)



Upvote if this helped you, please comment on this if there is an error!

0
Why is your event listener returning a value, and i'm going to have to downvote since there's waaaayyy too many comments, and you can definitely kick on the client side. But only yourself. User#24403 69 — 5y

Answer this question