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