I made a tool that drops pianos from the sky, they deal damage if they hit a player and then they explode. It works perfectly, except for the fact that every time that I drop two pianos around the same time interval, if they touch each other the connection for some reason never disconnects until the piano explodes…
Here’s the code
Connection = bombClone.Touched:Connect(function(hit)
local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if Player and Player.Team ~= user.Team then
Connection:Disconnect()
hit.Parent:FindFirstChildOfClass("Humanoid"):TakeDamage(35)
explode(bombClone, user)
elseif not Player then
Connection:Disconnect()
print(hit)
explode(bombClone, user)
end
end)
bombClone.Touched:Wait()
if Player and Player.Team ~= user.Team then
hit.Parent:FindFirstChildOfClass("Humanoid"):TakeDamage(35)
explode(bombClone, user)
elseif not Player then
print(hit)
explode(bombClone, user)
end
A case I see where it wouldn’t disconnect is if Player and Player.Team == user.Team is true. Perhaps it can be fixed if you move Connection:Disconnect() outside your if statement:
--above code
Connection:Disconnect()
if Player and Player.Team ~= user.Team then
--rest of the code
If bombClone.Touched:Once(function(hit)
local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if Player and Player.Team ~= user.Team then
Connection:Disconnect()
hit.Parent:FindFirstChildOfClass("Humanoid"):TakeDamage(35)
explode(bombClone, user)
elseif not Player then
Connection:Disconnect()
print(hit)
explode(bombClone, user)
end
end```