Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

5 comments

3

You're comparing a string with a table.

0

so what do i do instead?

0

you be smarter and get another way to compare all the creator's name

0

I'm not so sure it works when I do if name == "duckyo01" then

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

1 answer

✓ Accepted answer

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

1 comment

0

Thanks helped a lot

This discussion is preserved as it was. New answers, comments, and votes are closed.