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

Why does this script not give me the creator tag if I made a variable for all the creators names?

Asked by 7 years ago
local players = game:GetService("Players")
local gui = game.ServerStorage.Name_stats
local creatorsgui = game.ServerStorage.Creators

local function createGui(player, character)
    local gc = gui:clone()
    local cgc = creatorsgui:clone()
    local name = player.Name
    local level = player.leaderstats.Level
   local cnames = {"duckyo01", "tonymayhem" , "Bluefeather2011", "Bladedevv", "Verassi", "Sourskittles"}
    while character do
        wait()
if name == cnames then
    cgc.Parent = character.Head
    cgc.Nameandlevel.Text = "Creator | "..name.. ""
else
     gc.Parent = character.Head
        gc.Nameandlevel.Text = "" ..name.. " | Level: "..level.Value..""
    end
end
end
players.PlayerAdded:connect(function(player)
        player.CharacterAdded:connect(function(character)
            createGui(player, character) 
    end)
end)

Yes my main account name is duckyo01 so me typing my name wrong is not a reason.

3
You're comparing a string with a table. Goulstem 8144 — 7y
0
so what do i do instead? duckyo011 36 — 7y
0
you be smarter and get another way to compare all the creator's name hiimgoodpack 2009 — 7y
0
I'm not so sure it works when I do if name == "duckyo01" then duckyo011 36 — 7y
0
One way to check is to use a for loop or set your table such as [player]=true and then check if cnames[playername]==true then lukeb50 631 — 7y

1 answer

Log in to vote
2
Answered by
XAXA 1569 Moderation Voter
7 years ago
Edited 7 years ago

There are several things you can do to fix this script. One thing you can do is implement your names as a set. With a set, you can simply index the names to check if it is in the set, like so:

-- Convert your table into a set. You can probably write a function that does this for you...
local cnames = {
    duckyo01 = true,
    tonymayhem = true,
    Bluefeather2011 = true,
    Bladedevv = true,
    Verassi = true,
    Sourskittles = true
}

...

if cnames[name] then -- will be true or nil, depending on whether or not it is in the set
    ...

You can also try iterating through the list of names. Although this is slower if you're working with a large list of names (probably not enough to actually matter, though.)

local cnames = {"duckyo01", "tonymayhem" , "Bluefeather2011", "Bladedevv", "Verassi", "Sourskittles"}

...

local nameFound = false
for _, cname in pairs(cnames) do -- check each name in cnames
    if cname == name then -- if we find the name we were looking for
        nameFound = true -- then set nameFound to true
        break
    end
end

if nameFound then -- did we find the name that we were looking for?
    ...
0
Thanks helped a lot duckyo011 36 — 7y
Ad

Answer this question