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

Script not cloning GUI into PlayerGUI for Allowed players, anyone know how I can fix this??

Asked by 5 years ago
local Moderators = {"Sk3pticalR0BL0X"}  --Enter the names of players who can use the GUI.

----------------------------------
-- DO NOT EDIT BEYOND THIS LINE --
----------------------------------

game.Players.PlayerAdded:connect(function(GetMods)
    game.Lighting.KickGUI:Clone().Parent = game.Players[Moderators].PlayerGui
end)
0
**i have fixed my answer** WideSteal321 773 — 5y
0
and checked it WideSteal321 773 — 5y
0
that is not how a table works... use a loop greatneil80 2647 — 5y
0
That isn't how an array works either. greatneil80 2647 — 5y
View all comments (3 more)
0
free model, :connect() is in this along with those comments LoganboyInCO 150 — 5y
0
W is it a free model? WideSteal321 773 — 5y
0
i'm a little late (ok, maybe not a little), but no the comments are written for the other other devs. Sk3pticalR0BL0X 33 — 3y

1 answer

Log in to vote
0
Answered by
yHasteeD 1819 Moderation Voter
5 years ago
Edited 5 years ago

For first, :connect is deprecated. Use :Connect

You need to use a "For loop", for get moderator use generic for loop. example:

-- Generic for loop

-- Basically generic for loop have "index,value" the value is the string stored in a table, and index is "string position", example:

local Table = {"String1","String2","String3"}

 -- also you can use: i,v
for index,value in pairs(Table) do
    print("The index is: " .. tostring(index) .. " The value is: " .. tostring(value))
end


local moderators = {"Player1","Player2","Player3"}

game.Players.PlayerAdded:Connect(function(Player)
    -- if you use _,... or ...,_ the _ is a nil value, after you put _ you can't use this.
    for _,moderator in pairs(moderators) do -- Generic for loop, getting all strings in table
        -- if you use print(_) this return nil.
        if Player.Name == moderator then -- Check if Player Name is equal  to moderator name
            print("The player: " .. Player.Name .. " is a moderator!")
        end
    end
end)

For your script you can use this:

local Moderators = {"Sk3pticalR0BL0X"}  --Enter the names of players who can use the GUI.

----------------------------------
-- DO NOT EDIT BEYOND THIS LINE --
----------------------------------

game.Players.PlayerAdded:Connect(function(Player)
    for _,moderator in pairs(Moderators) do
        if Player.Name == moderator  then
            game.Lighting.KickGUI:Clone().Parent = Player:WaitForChild("PlayerGui")
  -- Lighting is not a good way to storage items, use ServerStorage for this.
        end
    end
end)

Wiki pages:

For loop

Hope it helped

0
my one did work. WideSteal321 773 — 5y
0
I recommend that you include some kind of note that tells the OP to not use Lighting as storage. User#25115 0 — 5y
0
use for loop is better yHasteeD 1819 — 5y
0
Also, it might be a good idea to have the admin UserId or name as the index so that you can simply check if they are an admin by doing if adminList[name] then or if adminList[UserId] then. User#25115 0 — 5y
View all comments (7 more)
0
That is a lot more efficient than a for loop. User#25115 0 — 5y
0
I don't think it would be necessary to add another check. yHasteeD 1819 — 5y
0
GUYS STOP DOWNVOTING WE GET IT WideSteal321 773 — 5y
0
yHasteeD, it would not be adding another check, it would be removing the for loop altogether and replacing it with a more efficient method. User#25115 0 — 5y
0
You can learn more about it in the second part of my answer, or in FredFishy's answer here: https://scriptinghelpers.org/questions/72402/how-do-i-remove-all-duplicates-of-a-array#68563 User#25115 0 — 5y
0
Not the same situation or problem, but the implementation of a hash table is what I am trying to get you to understand is more efficient than a for loop. User#25115 0 — 5y
0
Why call tostring on *what already is a string* User#24403 69 — 5y
Ad

Answer this question