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
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