local access = {"","",""}
local Player = game.Players.LocalPlayer
for i = 1, #access do
if access[i] == Player.Name then
script.Parent:remove - removes gui
else
script.Parent.Parent:findFirstChild(className == "Script"):remove() error here!
end
end
What did i do wrong on this script?
1 answer
There's a few things wrong in that code.
First of all, when you want to comment in a piece of Lua code, use two dash marks (--) and the rest of the line will be discarded by the Lua interpretter (what makes the code run)
To start with, Remove (and by extension remove) is a deprecated method. Basically that means you shouldn't use it. Use Destroy instead. Also, on line 7 there, should it ever execute, you will get an error because you did not correctly call the method. You need to add parentheses after the function name.
In the else branch, I'm not actually certain what you're trying to do. FindFirstChild takes a string as an argument - the Name of the child you are trying to 'Find'. This looks like you're trying to simply remove all Scripts from script.Parent.Parent?
local access = {"","",""}
local Player = game.Players.LocalPlayer
for i = 1, #access do
if access[i]:lower() == Player.Name:lower() then --Edited
script.Parent:Destroy()
else
local Children = script.Parent.Parent:GetChildren() --gets all Children of script.Parent.Parent
for i = 1, #Children do
if Children[i]:IsA("Script") then --This will catch both Scripts and LocalScripts, since LocalScripts 'extend' Scripts, even though they have the "LocalScript" classname.
Children[i]:Destroy() --Destroying a Script or LocalScript will also stop its code from continuing to run, whereas Removing it would not.
end
end
end
end
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Quick note: I'd change line 5 so that it compares each string in lower case by using the :lower() method on access[i] and Player.Name so that when you add a new name to the access array, you don't need to worry if you don't capitalise a name correctly.