The question is pretty simple I have a table of votes (all integer values), and I want to check if it’s a tie, so I want to just know how to check if two values in that one table are same or equal to each other?
if integertable[1]==integertable[2] then
1 and 2 would be the first and second values in the table.
for _, v in pairs(Table) do
for _, val in pairs(Table) do
if v == val then
print( "Found a match! " .. v .. " equals " .. val)
end
end
end
The inner loop has a duplicate reference to Table
and I think it’s not necessary in the case mentioned by the OP.
Doesn’t he want to check if there are two of the same values in the table? What that script is doing is iterating through the table, and then inside that iteration it iterates through the same table again to see if there are any matches.
function duplicatesExist(arr) --returns true if two or more values in array equal, false otherwise
local hash = {}
for i = 1, #arr do
local v = arr[i]
if hash[v] == nil then
hash[v] = i
else
return true
end
end
return false
end
Make the source of value the comparison
I am comparing a group of players who are closest to the screen
The name of the player closest to the screen appears on the screen
As in the picture
Danielmasterlions Closest to the screen
Jacobtheherowrestler Closest to the screen
Put this program in every player
local Enable = true
while true do
wait()
Enable = true
local Pillar = game.Workspace.Pillar
local ClosestValue = game.Workspace.ClosestValue
local DistanceTable = {}
for _, character in pairs(workspace:GetChildren())do
if character.Name ~= script.Parent.Name then
local humanoid = character:FindFirstChild(“Humanoid”)
local root = character:FindFirstChild(“HumanoidRootPart”)
if root ~= nil and humanoid ~= nil and humanoid.Health > 0 then
local Distance = (root.Position - Pillar.Position).magnitude
–print(Distance)
DistanceTable[#DistanceTable + 1] = Distance
end
end
end
for index = 1, #DistanceTable do
–print(index, DistanceTable[index])
local Myroot = script.Parent:FindFirstChild(“HumanoidRootPart”)
local MyDistance = (Myroot.Position - Pillar.Position).magnitude
if MyDistance > DistanceTable[index] then
Enable = false
end
end
print(Enable)
if Enable == true then
ClosestValue.Value = script.Parent.Name
end
end
You want the two values to be the same, and I know that
If you are close to what you want to do, I will send you the file containing all the details
right now using this, it works, but I want it to only delete the duplicated value, not both. For example, it finds 2 values that are the same, but destroys both of them. How can I make it only destroy 1?