✓ Accepted answer
You have to use workspace.Spikes:GetChildren() to get a list of the children of the Spikes model and a for loop to go through each child inside the list of children. Lists in lua are called "tables", so I will refer to them as tables from now.
Here is how you would go through the children inside the Spikes model:
for key, value in pairs(workspace.Spikes:GetChildren()) do
print(value.Name)
end
key is a number, indicating the order the child is in inside the GetChildren table, and value is the child object itself. We can rename key and value to better names:
for _, spike in pairs(workspace.Spikes:GetChildren()) do
print(spike.Name)
end
key has been renamed to _ because variables that aren't used are usually named _.
value has been renamed to spike because the children are the spike parts.
So here is how you apply your script to all the spikes inside the workspace.Spikes model:
for _, spike in pairs(workspace.Spikes:GetChildren()) do
local debonce = false
spike.Touched:Connect(function()
if not debonce then
debonce = true
health.Value = health.Value - 1
wait(5)
debonce = false
end
end)
end
2 comments
I like your explanation
I just commend you for the in depth explanation. Cheers