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
01local players = game:GetService("Players")
02local gui = game.ServerStorage.Name_stats
03local creatorsgui = game.ServerStorage.Creators
04 
05local function createGui(player, character)
06    local gc = gui:clone()
07    local cgc = creatorsgui:clone()
08    local name = player.Name
09    local level = player.leaderstats.Level
10   local cnames = {"duckyo01", "tonymayhem" , "Bluefeather2011", "Bladedevv", "Verassi", "Sourskittles"}
11    while character do
12        wait()
13if name == cnames then
14    cgc.Parent = character.Head
15    cgc.Nameandlevel.Text = "Creator | "..name.. ""
View all 26 lines...

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:

01-- Convert your table into a set. You can probably write a function that does this for you...
02local cnames = {
03    duckyo01 = true,
04    tonymayhem = true,
05    Bluefeather2011 = true,
06    Bladedevv = true,
07    Verassi = true,
08    Sourskittles = true
09}
10 
11...
12 
13if cnames[name] then -- will be true or nil, depending on whether or not it is in the set
14    ...

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

01local cnames = {"duckyo01", "tonymayhem" , "Bluefeather2011", "Bladedevv", "Verassi", "Sourskittles"}
02 
03...
04 
05local nameFound = false
06for _, cname in pairs(cnames) do -- check each name in cnames
07    if cname == name then -- if we find the name we were looking for
08        nameFound = true -- then set nameFound to true
09        break
10    end
11end
12 
13if nameFound then -- did we find the name that we were looking for?
14    ...
0
Thanks helped a lot duckyo011 36 — 7y
Ad

Answer this question