My script is supposed to remove the health of a building. It doesn't work. No errors.
Script:
game.Players.PlayerAdded:Connect(function(player)
local debris = player:WaitForChild("leaderstats").Debris
while true do
wait(1)
repeat wait (1) until game.Workspace:FindFirstChild("Map")
local ClonedMap = game.Workspace:WaitForChild("Map")
wait(2)
for i,v in pairs(ClonedMap.Buildings:GetChildren()) 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 - player:FindFirstChild("Morph").Damage.Value
if v:FindFirstChild("Health").Value == 0 then
v:Destroy()
print("Building destroyed.")
end
player.leaderstats.Debris.Value = player.leaderstats.Debris.Value + 10
end
end)
end
end
end
end
end)

2 comments
Explain your question more please!
A map spawns in workspace. This gets the buildings in the map, checks if a player is touching them, then removes health. There are ~ 200 such buildings.