How to make a part fling non-admins but not fling admins

I need a way to make a part fling non-admins, but not fling admins. I never searched it up, neither do I think this was ever discussed. The Admins will be like:

local admins = {"STOPEATCAK","QuiltRecovery"}

If you can help me with this, Thanks!

1 Like

I’d suggest using UserID’s just incase the usernames change

Anyways, on to the question: You could use a for loop to check if they’re an admin

local isAdmin = false --Assume at the start the player is not an admin
for i,v in pairs(admins) do --The aforementioned for loop
  if Player.Name == v then --If the player's name matches an admin name,
    isAdmin = true --They are an admin
    break --Stop checking for this player
end

EDIT: Lol i forgot table.find() was a thing so use that instead of a for loop

1 Like

Handler: (ServerScriptService)

local Admins = {
 000000, -- UserId
 000000, -- UserId
}
game.Players.PlayerAdded:Connect(function(plr)
  local Bool = Instance.new("BoolValue")
  Bool.Name = "IsAdmin"
  Bool.Parent = plr
  Bool.Value = false
  
  wait()

  for _, v in pairs(Admins) do
    if v == plr.UserId then
       plr.IsAdmin.Value = true
    end
wait()
  end
end)
2 Likes

Thanks! I will edit this and hopefully get it working

1 Like

That script only can used in 1 script.
My script make bool value to each player. so we can check at every script!

1 Like

Adding onto the above responses, you don’t have to loop through every element in the admins table. You can simply use:

local isAdmin = table.find(admins,player.UserId) ~= nil
2 Likes

The final Script:

local Admins = {
 000000, -- UserId
 000000, -- UserId
}
game.Players.PlayerAdded:Connect(function(plr)
  local Bool = Instance.new("BoolValue")
  Bool.Name = "IsAdmin"
  Bool.Parent = plr
  Bool.Value = false
  
  wait()

local isAdmin = table.find(Admins, plr.UserId) ~= nil

if isAdmin then
 plr.IsAdmin.Value = true
end

end)
1 Like

Simple solution to your problem:
This script loops through all the players. If the player’s id matches an id in the admins table, then it will cancel the fling and continue looping for other players.

local admins = {"000000000", "000000000"} -- put the ids of the admins here

for i, v in pairs(game.Players:GetPlayers()) do
      if table.find(admins, v.UserId) ~= nil then continue end -- if the player's userid matches with an id in the admins table, it will cancel the fling and continue the loop.
      -- fling script
end

This script is way more efficient than putting a value into each player and checking that.

3 Likes

We only can use this script in 1 script.

1 Like

also If new player join, we cant check isAdmin.

1 Like

by good programming practices it should only happen in one script, if OP desired to extend it, @enpiesie ’s solution is extensible to a modulescript managing objects for infinite parts that fling players without additional scripts. Boolean values parented to the players may introduce more overhead than is needed with the additional memory required to hold an instance and the need to assert the instance exists before referencing it

3 Likes

You just put the for loop in a function and call it whenever you need it.
I thought this was obvious?

1 Like

You can copy and modify the script to run when a certain condition is met, for example when a player types a command in chat. You can simply put it in a function and run it whenever it’s needed.

Thanks :DDD
i am now happy : )

2 Likes

@STOPEATCAK I messed up. I switched return and continue. In the old version, it would cancel the whole fling loop if it encountered an admin. I replaced return with continue and that way it should cancel the fling only for the admin and continue looping for the other players. Sorry and thanks for understanding :]

oh alright, thank you for fixing it

1 Like

Hey. I’m not sure if you have to use continue or return. I’m pretty sure it’s return, but I’m not sure. I looked up the use of continue and it would to the opposite of return? So, please, test the code with return and the code with continue separately to see which one works. Sorry and thank you!

I will test this later, thanks in advance : )

1 Like