Whenever the gun fires, it inserts the damage script inside the bullet for it to check for collisions and deal damage. I have been trying countless ways to remove the bullet but it always ends up getting destroyed from the start or does not even get destroyed. Currently it does not even remove the bullet and I don't understand why because my code seems fine.
damageCheck = false
script.Parent.Touched:Connect(function(hit)
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr, h, mouse)
if hit.Name == "Handle" then return end
local h = hit.Parent:FindFirstChild("Humanoid")
if h then
if hit.Parent.Name ~= plr.Name then
h:TakeDamage(10)
damageCheck = true
end
end
damageCheck = true
end)
end)
while script.Parent do
if damageCheck == true then
script.Parent:Destroy()
end
wait(.1)
end
