My main objective:
I want to see if its possible to detect if a player collided with a part within a table, Rather than using individual scripts to detect if a player touched a part.
local test = {
game.Workspace.Platform_1,
game.Workspace.Platform_2,
game.Workspace.Platform_3,
game.Workspace.Platform_4
}
So with these different parts in the table I’d want to check if a player touched a part in it, Any ideas on how I could do that.
I don’t have much experience with tables so just need some help figuring it out.
local test = {
game.Workspace.Platform_1,
game.Workspace.Platform_2,
game.Workspace.Platform_3,
game.Workspace.Platform_4
}
game.Workspace.SpawnLocation.Touched:Connect(function(Hit)
if table.find(test, game.Workspace.Platform_1) and Hit.Parent:FindFirstChild("Humanoid") then
end
end)
If you would like to do it automatically then you could loop through the table
local test = {
game.Workspace.Platform_1,
game.Workspace.Platform_2,
game.Workspace.Platform_3,
game.Workspace.Platform_4
}
for i, Part in pairs(test) do
Part.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
end
end)
end
local test = {
game.Workspace.Platform_1,
game.Workspace.Platform_2,
game.Workspace.Platform_3,
game.Workspace.Platform_4
}
for i, testPart in pairs(test) do
print(i, testPart) -- Not needed, but will be useful for you to see what this for loop is doing :)
testPart.Touched:Connect(function(touchPart)
-- Logic to see if `touchPart` is from a players' character
end)
end
That was a possibility I was thinking, but wouldn’t that be difficult to go through every single part just to find the one specific part the player is touching upon.