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
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)
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
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