Ok so how to I modify a certain table when a certain thing is hit

since I want to do this

Hello = {}

when a part touches it I want to make the parts name corrspent with the value it will insert it to

for example if a part named hello is touched I want it to insert it into the table Hello

my current code:

AirBaseMapVote = {}

RockMapVote = {}
SkyMapVote = {}

StringToArray = function(String)
local Array = {}
for i = 1, String:len() do
table.insert(Array, String:sub(i,i))
end
return Array
end

for i,v in pairs(script.Parent:GetChildren()) do
if v.Name ~= “Script” then
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
print(“hi”)

			local Hello = StringToArray(tostring(v))
			
			table.insert(Hello, hit)
		end
	end)
end

end

while true do
print(#AirBaseMapVote)
print(#RockMapVote)
print(#SkyMapVote)

wait(1)

end

I cant do this manually for each part tho thats why I need to do this
I really need to do this for a advanced voting system im making

It’s pretty simple!

local PlayersTable = {}

local Part = workspace:WaitForChild(PartName) 

local function checkTable(PlayerInstance,...) 
     assert(not type(PlayerInstance) == "Player", "Has to be a player instance.")
      for index,value in next, PlayersTable do 
             if value == PlayerInstance then
                table.remove(PlayersTable,index) 
           else 
               PlayersTable[#PlayersTable + 1] = PlayerInstance 
         end
      end
end
Part.Touched:Connect(function(Hit) 
      local Humanoid = Hit.Parent:FindFirstChildOfClass("Humanoid") or 
     Hit.Parent.Parent:FindFirstChildOfClass("Humanoid")

    if Humanoid then 
        local Player = game.Players:GetPlayerFromCharacter(Humanoid.Parent)
        checkTable(Player)
   end
end)
1 Like

You should also add a debounce too!

Thanks! oh also btw do you know how to convert an object into a table?

You could just do :

local PlayersTable = {object = 2}

Oh but the problem is when I convert a string into a table it doesnt work it doesnt add it to the real table

AirBaseMapVote = {}
RockMapVote = {}
SkyMapVote = {}

StringToArray = function(String)
local Array = {}
for i = 1, String:len() do
table.insert(Array, String:sub(i,i))
end
return Array
end

for i,v in pairs(script.Parent:GetChildren()) do
if v.Name ~= “Script” then
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
print(“hi”)

			local Hello = StringToArray(tostring(v))
			
			table.insert(Hello, hit)
		end
	end)
end

end

while true do
for i,v in pairs(SkyMapVote) do
print(v)
end
wait(1)
end

Ok bro I am sorry I really wasnt looking for the script you posted above my question was how do I change an object into a table value

since I want to do this

Hello = {}

when a part touches it I want to make the parts name corrspent with the value it will insert it to

for example if a part named hello is touched I want it to insert it into the table Hello

I cant do this manually for each part tho thats why I need to do this

StringToArray = function(String)
local Array = {}
for i = 1, String:len() do
    table.insert(Array, String:sub(i,i))
end
return Array

end

for i,v in pairs(script.Parent:GetChildren()) do
if v.Name ~= “Script” then
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
print(“hi”)

			local Hello = StringToArray(tostring(v))
			
			table.insert(Hello, hit)
		end
	end)
end

end

This didnt work because when I checked what values were in the table with a while true do loop it didnt print any values

Do you have anything I could contact you easily with? I would like to show you how this works and etc

discord Cool#1045 thats my discord u can contact me there