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

How to exclude player's from a function?

Asked by
IXLKIDDO 110
9 years ago

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.

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 alphawolvess 1784 — 9y

1 answer

Log in to vote
0
Answered by
Wizzy011 245 Moderation Voter
9 years ago

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.

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. IXLKIDDO 110 — 9y
Ad

Answer this question