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

Script not cloning GUI into PlayerGUI for Allowed players, anyone know how I can fix 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(GetMods)
	game.Lighting.KickGUI:Clone().Parent = game.Players[Moderators].PlayerGui
end)

7 comments

0

i have fixed my answer

0

and checked it

0

that is not how a table works... use a loop

0

That isn't how an array works either.

0

free model, :connect() is in this along with those comments

0

W is it a free model?

0

i'm a little late (ok, maybe not a little), but no the comments are written for the other other devs.

1 answer

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

11 comments

0

my one did work.

0

I recommend that you include some kind of note that tells the OP to not use Lighting as storage.

0

use for loop is better

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.

0

That is a lot more efficient than a for loop.

0

I don't think it would be necessary to add another check.

0

GUYS STOP DOWNVOTING WE GET IT

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.

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

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.

0

Why call tostring on what already is a string

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