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

How can I iterate a table?

see i asked a friend why my holo script wasn't working, and he said because on line 5 I used gidranks instead of an integer, and he said in order to fix it I would need to iterate through a table, I asked how and he never responded, so I am asking you guys, Any help would be appreciated!

Here is the script.

local admins ={"EmperorVolvax"} -- What Users(Needs to be EXACT)
local gid = 1173040 -- What group is needed
local gidranks = {255,105,104,103,102,101} -- What Ranks you want to be used
--Dont Mess with the Below --
game.Players.PlayerAdded:connect(function(Player)
	if Player:GetRankInGroup(gid) == gidranks then
		for _,v in pairs(admins)do
			Player.Chatted:connect(function(msg)
				if msg == "load sft" then
				x = game.ServerStorage.sft:Clone()-- Change sft to the map in serverstorage
				if game.ServerStorage.sft.Name == "sft" then 
					local h = Instance.new("Hint")
					h.Parent = game.Workspace
					h.Text = "Loading Facility:// SwordFight"
					wait(2)
					h:Destroy()
					x.Parent = game.Workspace
				end
				end
			end)
		end
	end
end)

1 answer

✓ Accepted answer

== means "is equal to", but a better description might be "is the same as".

GetRankInGroup's name suggests it returns a rank. But gidranks is a list of a ranks.

No rank is the same as a list of a ranks -- they aren't the same sort of thing.


I'm assuming what you wanted to check is "if gidranks contains this rank".

Sadly Lua doesn't have "contains" built in. But it's really easy to write. You just make a for loop go over everything in the table with pairs, and return true if the thing in the table is the thing you're looking for

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

You can then just ask if contains(gidrank, Player:GetRankInGroup(gid)) then to get exactly that.

2 comments

0

Dangit Blue, I wanted to give a legit answer.

0

Thank you!

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