Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would you add more usernames?

if game.Players.LocalPlayer.Name == "username 1" then

How would I add more usernames?

2 comments

0

Replace "username" with {"BoogaBoogaHolder123","Username"}

0

Unless you want this to be client-sided, do this in a regular script.

2 answers

✓ Accepted answer

Okay, your best bet is to use an array storing all the usernames. That way you don't have to keep using 'or' since it's an operator.

I am not entirely sure why you are using a LocalScript for your checks since this can be abused by exploiters, but it's your personal preference I guess.


Players = game:GetService('Players')
Player = Players.LocalPlayer

local usernameList = {'bob123', 'username', 'robloxadminguy123'} -- Store all the usernames here.

function checkUsername(Player)
	local nameString = Player.Name
	for _,v in pairs(usernameList) do -- loop through the table
		if string.lower(v) == string.lower(nameString) then -- use string.lower for cap sensitivity
			return true -- if username found, return true
		end
	end
	return false -- otherwise no username found, false
end

if checkUsername(Player) then
	-- rest of code here
end -- end the if statement

A breakdown of the code would be, the array stores the data and the function loops through that data to check if a string matches the data, if it does then it'll pass the if statement.

Use the **or **statement

ex:




if game.Players.LocalPlayer.Name == "username 1" or "username 2" or "username 3" then

1 comment

0

-1 for "or statement" (it's an OPERATOR), and for not using it correctly and for not using tables

This discussion is preserved as it was. New answers, comments, and votes are closed.