What I see in most obstacle courses are kill bricks which all contain a script that handles the .Touched event which kills the player when touched. This is extremely inefficient because sometimes people create many instances without keep their code dry.
- D on't
- R epeat
- Y ourself
What you could just do is name every kill brick "Kill Brick" and then make a script in ServerScriptService which contains the following code:
for _, killBrick in pairs(workspace:GetChildren()) do if killBrick:IsA("BasePart") and killBrick.Name == "Kill Brick" then killBrick.Touched:connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then humanoid.Health = 0 end end) end end
Boom! It took just 10 lines to make all of the kill bricks in the game function properly.