local debounce = false
part.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player and not debounce then
debounce = true
part:Destroy()
end
end)
this part is destroyed when a player touches it.Is it necessary to apply the Debounce technique taking into account that when the part is destroyed all its connections are cancelled (disconnected)?
And the same question for when I only perform the disconnection as in this code.
local debounce = false
local connection
connection = part.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player and not debounce then
debounce = true
connection:Disconnect()
end
end)
part.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
part:Destroy()
end
end)
local connection
connection = part.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
connection:Disconnect()
end
end)
When an object is destroyed, all connections to that object’s events are disconnected automatically, therefore you don’t need to explicitly destroy that other connection yourself.