I made a script so that when a player touches a building, will give that player matter and destroy the building. The only problem is that it doesn’t give any matter. I don’t have any output errors, what is happening? Here’s my 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("ClonedMap") local ClonedMap = game.Workspace:WaitForChild("ClonedMap") local Large_Buildings = ClonedMap:WaitForChild("Large_Buildings") local Small_Buildings = ClonedMap:WaitForChild("Small_Buildings") wait(2) for i,v in pairs(Large_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:Destroy() player.leaderstats.Matter.Value = player.leaderstats.Matter.Value + 10 print(player.Name.." destroyed a large building!") end end) end end end for i,v in pairs(Small_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:Destroy() player.leaderstats.Matter.Value = player.leaderstats.Matter.Value + 10 print(player.Name.." destroyed a small building!") end end) end end end end end)