from what I understand, while loops can be very demanding to a player's gameplay, slowing the game down. So while I was making this I could find no other way of doing this without a while loop. Is there a better way to check if a part in a table has been touched?
My attempt:
local model = game:GetService("Workspace").Model local table = {} for i,v in pairs (model:GetChildren()) do -- This part is different, It's for the sake of the site table.insert(table,#table+1,v) end for i,v in pairs(table) do v.Touched:Connect(function() print("Touched") end) end
You can actually use a single table [as called by :GetChildren()] to run this function
local model = workspace:WaitForChild("Model") local function Fired() print("Touched") end for _, parts in pairs(model:GetChildren()) do parts.Touched:Connect(Fired) end
If you use a local event, then by using the for loop to check the array, anytime an iterated part is touched, this pre-defined function will fire.