I made a script that lowers the health of a building that you are touching every 1 second. I have an IntValue in each building that is called Health. My script is:
game.Players.PlayerAdded:Connect(function(player) local debris = player:WaitForChild("leaderstats").Debris while true do wait(1) repeat wait (1) until game.Workspace:FindFirstChild("ClonedMap") local ClonedMap = game.Workspace:WaitForChild("Map") local destructible = ClonedMap.Buildings:GetChildren() wait(2) for i,v in pairs(destructible) do for a,k in pairs(v:GetChildren()) do if k:IsA("Part") or k:IsA("BasePart") then k.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then v:FindFirstChild("Health").Value = v:FindFirstChild("Health").Value - game.Players.LocalPlayer:FindFirstChild("Morph").Damage.Value if v:FindFirstChild("Health").Value == 0 then v:Destroy() print("Building destroyed.") end game.Players.LocalPlayer.leaderstats.Debris.Value = game.Players.LocalPlayer.leaderstats.Debris.Value + 10 end end) end end end end end)
No errors in the output. It's also meant to check if what you are touching is a building, hence "destructible," then give you a currency called debris.