I am trying to prevent touch from firing more then once, i have tried debouncing adding to tables and nothing is working to stop it.
function fireTorpedo(v)
this.MainPart.FirePhoton:Play()
local t = Instance.new("Part",workspace)
t.CanCollide = true
t.Anchored = false
t.Size = Vector3.new(0.2,0.2,0.4)
t.BrickColor = BrickColor.new("Really red")
t.Material = "Neon"
local m = Instance.new("SpecialMesh",t)
m.MeshType = "Sphere"
local l = Instance.new("PointLight",t)
l.Color = Color3.new(1,0,0)
local bv = Instance.new("BodyVelocity",t)
local pos = (this.Model.TorpedoTube.CFrame*CFrame.new(3*torp_tube,0,-4)).p
local dir = (v) and (v - pos).unit or this.Model.TorpedoTube.CFrame.lookVector
t.BodyVelocity.velocity = this.MainPart.Velocity + dir*200
t.CFrame = CFrame.new(pos,pos + dir)
torp_tube = -torp_tube
t.Touched:connect(function(hit)
local p3 = Instance.new("Part")
p3.Transparency = 1
p3.Anchored = true
p3.CanCollide = false
p3.Size = Vector3.new(0.2,0.2,0.2)
p3.Parent = game.Workspace
p3.Position = t.Position
game:GetService("Debris"):AddItem(t)
game:GetService("Debris"):AddItem(p3, 0.75)
local ex = Instance.new("Explosion")
ex.BlastPressure = TorpedoBP
ex.BlastRadius = TorpedoBR
ex.DestroyJointRadiusPercent = 0
ex.Position = p3.Position
ex.Parent = workspace
local modelsHit = {}
local HarmFireFX = this.MainPart.HarmFireFX:clone()
HarmFireFX.Parent = p3
HarmFireFX.Enabled = true
local HarmShotLight = this.MainPart.HarmShotLight:clone()
HarmShotLight.Parent = p3
HarmShotLight.Enabled = true
ex.Hit:Connect(function(part, distance)
local parentModel = part.Parent
if parentModel then
if modelsHit[parentModel] then
return
end
modelsHit[parentModel] = true
local humanoid = parentModel:FindFirstChild("Humanoid")
if humanoid then
local distanceFactor = distance / ex.BlastRadius
distanceFactor = 1 - distanceFactor
humanoid:TakeDamage(TorpedoDamagePlayer * distanceFactor)
end
end
end)
local debounce = false
t.Touched:Connect(function(hit)
local modelsHitTorp = {}
local parentModel = hit.Parent
if parentModel then
if modelsHitTorp[parentModel] then
return
end
modelsHitTorp[parentModel] = true
local VehicleHealth = parentModel:FindFirstChild("VehicleHealth")
local GateshipShield = parentModel:FindFirstChild("GateshipShield")
while debounce == false do
debounce = true
print ("True Debouncing")
if VehicleHealth and not GateshipShield then
print ("Hull Hit Torpedo")
hit.Parent.VehicleHealth.Value = hit.Parent.VehicleHealth.Value - TorpedoDamageShuttle
end
wait(1)
debounce = false
print ("False Debouncing")
end
end
end)
local modelsHitTorp = {}
local parentModel = hit.Parent
if parentModel then
if modelsHitTorp[parentModel] then
return
end
local GateshipShield = parentModel:FindFirstChild("GateshipShield")
local ShieldHealth = parentModel:FindFirstChild("ShieldHealth")
if ShieldHealth and GateshipShield then
print ("Shield Hit Torpedo")
hit.Parent.ShieldHealth.Value = hit.Parent.ShieldHealth.Value - TorpedoDamageShuttle
end
end
end)
end

1 comment
Just made it a lot worse, went up to 200 or so touches