How to call a value from a table

I’m not great with tables, but how would you compare an instance or string to a table, then return the number in the order of the table they are? I’m not even sure if this is possible, but basically I am trying to remove a player value from a table when they exceed a certain threshold.

Hm I guess you can use something like this
table["plrname"] = yourvalue
You can check every player in players and give to player a value

local players = {}
for i,player in ipairs(game.Players:GetChildren()) do
players[player.Name] = 0
end

And then check it.

local yourthreshold = 0
for i,player in ipairs(game.Players:GetChildren()) do
    if players[player.Name] > yourthreshold then
        -- do something
    end
end

How would i tell what number the player is in the table? If i had the string and/or instance

I guess something like this

local string = "plr"
local yourval = players[string]

i am not sure that I understood what are you saying about :pensive:

also you can put instance in table.

I would be very grateful if you could show me with a good example what you need exactly.

You could loop through the table and increment the value by one everytime it loops, Then check if the Index is what you want. (In that case, The Index would be the Player’s Name)

-- Dictionary
local PlayersInGame = {
	["Crunch"] = true,
	["ROBLOX"] = true,
	["Builderman"] = true
}

-- Initial Value will be 0
local LoopIndex = 0

-- Loop
for Index, Value in pairs(PlayersInGame) do
	-- Increment the LoopIndex by 1.
	LoopIndex += 1
	if Index == "ROBLOX" then
		-- We are currently at ROBLOX.
		-- Now we can stop the loop by breaking it!
		print("The Index at", LoopIndex, "is ROBLOX!")
		break
	end
end
1 Like

If the player gets too close, it adds them to the table, and removes them when they walk away.

You can check every character in the server
and loop this.

for i,v in ipairs(workspace.Characters:GetChildren()) do
		local human = v:FindFirstChild("Humanoid")
		local torso = v:FindFirstChild("Torso") or v:FindFirstChild("HumanoidRootPart")
		if human and torso and v.Name ~= script.Parent.Name then
			if (part.Position - torso.Position).magnitude < dist and human.Health > 0 then
				table.insert(potentialTargets,torso)
			end
		end
	end