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

What did i do wrong on this script?

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
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


1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

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
1
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. Spongocardo 1991 — 10y
Ad

Answer this question