Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.