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

How to exclude player's from a function?

So far, what I have done is created this bit of code.

CheckIfAllowed = true

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(CheckIfAllowed)
		if plr == [INSERT NAME HERE] then return false
		end
	end)
end)

if CheckIfAllowed then -- Past here is working code

What I wanted to do is make it so that certain people are exempt from certain functions. However, this doesn't appear to be working. I wanted to know if there's any way to do this or not? Also, if someone can also tell me how to make a list of players from a local or something else like that instead of having the [INSERT NAME HERE] (so that it checks multiple people) it would be much appreciated.

1 comment

0

In line 5, it should be a string like this: ["The Players Name"], also your argument in line 4 shouldn't be a bool

1 answer

✓ Accepted answer

The current issue with your script is, you should have plr.Name not just plr on line 5, as currently you're trying to check the actual player instance against a string, instead of the player's name.

To check multiple people, you could have a table inside your code:

local tableofexclusions = {"Name1", "Name2", "Name3"}

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(CheckIfAllowed)
		for i,v in pairs(tableofexclusions) do
			if v == plr.Name then
				return false
			end
		end
	end)
end)

This 'For' loop will check the player's name against every name inside the table.

1 comment

0

The 10th line though is supposed to have a close parentheses at the end of the "end". So like this "end)". Just a note, but thank you.

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