Hi. What we want to look at is for loops, and the :GetChildren() and/or :GetDescendants() functions. How these work is they return an array with a list of all objects in a folder or model, so that they can be interacted with by a script.
First thing you're going to want to do is find some way of grouping all the parts. If you can put them in one folder in the workspace, that would be ideal, but if you can't, we can find them by name (which is what I assume you're doing right now.)
for i,child in pairs(game.Workspace:GetDescendants()) do
if child.Name == "TouchPart" then
child.Touched:Connect(function(Hit)
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Player then
Player:LoadCharacter()
end
end)
end
end
If you have any more questions about this or how any of this code works, let me know.
3 comments
if Player.Name == "The name you want" then Player:LoadCharacter().
But, how would the player touch the part if he doesn't have a body? (Lenny)
its supposed to be that if the player walks on any brick with a specific name, for example "lava" then they get respawned