I want to pass two arguments to the table for future search. When faced with a Part, who (the player’s name) and what (which part of the body) will be entered in the table, after which you will need to search the table for who and what touched. Help guys who have come across something similar.
local part = {}
script.Parent.Touched:Connect(function(hit)
if hit.Parent then
local canTop = hit.Parent:FindFirstChild('canTop')
if canTop then
table.insert(part, hit.Parent.Name)
print("can")
end
end
end)
script.Parent.TouchEnded:Connect(function(hit)
if hit.Parent then
local canTop = hit.Parent:FindFirstChild('canTop')
if canTop then
if table.find(part, hit.Parent.Name) then
end
print("cant")
end
end
end)
I have now tried to add not the players name but the player as an object to the table, and if the touch was started by HumanoidRootPart and finished by HumanoidRootPart, then remove the player from the list
if table.find(part, hit.Parent.Name) and hit.Name == 'HumanoidRootPart' then
table.remove(part, hit.Parent)
end
I have solved the issue. Instead of adding two parameters, I made sure that Part concerns one part of the player and remembered the player by writing it to the table. When this part stopped touching the Part, I removed the player from the matrix.
local part = {}
script.Parent.Touched:Connect(function(hit)
if hit.Parent then
local canTop = hit.Parent:FindFirstChild('canTop')
if canTop then
if table.find(part,hit.Parent.Name) == nil and hit.Name == 'HumanoidRootPart' then
table.insert(part, hit.Parent)
end
end
end
end)
script.Parent.TouchEnded:Connect(function(hit)
if hit.Parent then
local canTop = hit.Parent:FindFirstChild('canTop')
if canTop then
if table.find(part, hit.Parent) and hit.Name == 'HumanoidRootPart' then
table.remove(part, table.find(part, hit.Parent.Name))
end
end
end
end)