Im attempting to create a whitelist for projectiles. player names put into the whitelist will be ignored by certain projectiles.
I currently have a folder owned by each player and I want to give each player their own whitelist into the folder.(the folder is stored in the workspace).
I think I may have to use a table filled with names chosen by the player, but my problem is sharing that information to projectiles in the workspace so they can check to see if what they are about to hit is whitelisted. thanks for any help you can give me.
You could always use BindableEvents to send the table across each script. Alternatively you could use a global variable (_G).
You can use CollectionService for this, adding tags to everything that needs to be whitelisted. When you want to check if what a projectile is going to hit is whitelisted you can just use HasTag on whatever is about to be hit.
I plan to have the projectile get the players whitelist which will be stored in the workspace, my new problem now is to compare “hit.Parent.Name” to everything within a table. what kind of for loop should I use? or should I use something else?
You could also use a ModuleScript.
I never learned how to use modulescripts.
Hey, check out this article:
ModuleScripts look sort of confusing at first; when they initially came out, I hadn’t been using Roblox so when I came back they were a bit confusing. They’re basically global scripts that you can write to and read from from any server script in the game, so long as you require it.
I think all I need now is a way to go through a table and compare it to “hit.Parent.Name”, what loop should I use?
If you write the players you intend to whitelist into a table in the ModuleScript, you can require the ModuleScript and check to see if that player is in the table, which you can then use to decide what happens if a player touches the part.
You can have a function that writes player names to a global table called
whiteList by using
whiteList[player] = true inside the ModuleScript and then use another function to return to the script if
whitelist[player] == true , thus giving you the option to set what action the projectile takes depending on the return value.
Edit: In my game I sort of do something along these lines.
I use an onTouched function from a part in workspace which writes to a ModuleScript and puts the player in a table named
completed and sets their value to true. As I run the onTouched function in workspace, I use this as my next line of code(where
didPlayerComplete is a function inside of the ModuleScript which returns whether or not the player is in the table and marked as
true) which breaks the function if that is the case.
if not player or module.didPlayerComplete(player) then return end;