Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I remove the bullet when it hits something (filtering enabled is on)?

Asked by 5 years ago

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

1 answer

Log in to vote
0
Answered by
Mowblow 117
5 years ago

If you are using a remote event to replicate the bullets to the server, make sure that a server script within the bullet checks for the hit server side. Doing so from the client would mean that the bullet is deleted on the client but not the server, of which may be the issue. I wouldn't check for hits or add damage from the client side. Other than that, the code seems fine.

Ad

Answer this question