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

Not sure what is wrong with this script, I've tried debugging?

Asked by 10 years ago

The following script is not doing what it is intended to do, it is intended to check to see if a player is "banned", if they are banned text becomes visible saying "you are banned" if not it checks to see if the GUI menu is opened, if it is the GUI menu closes, if it isn't it opens. Below is the code.

local plyr = script.Parent.Parent.Parent.Parent.Parent
local Idea = script.Parent.Parent.IdeaGUI
local Button = script.Parent

function IdeaFunction()
    if plyr.Name == {"EmperorD"} then
        script.Parent.Parent.banned.Visible = true
    else if Idea.Visible == true then
        Idea.Visible = false
        Button.Text = "Open"
    else if Idea.Visible == false then
        Idea.Visible = true
        Button.Text = "Close"
    end
    end
    end
    end

script.Parent.MouseButton1Down:connect(IdeaFunction)

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

You compare plyr.Name and {"EmperorD"}.

But plyr.Name is text, and {"EmporerD"} is a list. A list and text will never be equal, just based on them having different types. (One banana and one dog are never the same; we don't need to know anything more after knowing they are different kinds of things)


When you say ==, you're asking "are these the same".

Your intent for that line was "is plyr.Name contained within {"EmporerD"}* -- so that is what you should write.

function contains(list, element)
    for i,v in pairs(list) do
        if v == element then
            return true
        end
    end
end

.....

    if contains( {"EmporerD" }, plr.Name ) then

etc.

Ad

Answer this question