So I have a raycast weapon that can hit any humanoid and decrease it's health. It checks if the humanoid is at 0 health or below then sends a remote event to a server script then the server script gives the player score. I have a problem where the player can still attack the dead humanoid multiple times before it despawns thus getting a lot of points per kill.

Adding a timed debounce is not an option since the player will not be able to get rewards from killing other NPCs until the debounce is over.

Local script (Weapon):

if hit and hit.Parent:FindFirstChild("Humanoid") then
		if hit.Parent.Humanoid.Health <= 0 then
		
		remoteEvent:FireServer()
		end
	end

Server script:

local remoteEvent = game.ReplicatedStorage:WaitForChild("KillEvent")

remoteEvent.OnServerEvent:Connect(function(player, tagClone)
	local points = player:WaitForChild("leaderstats"):WaitForChild("Points")
	
	points.Value = points.Value + 1
end)

1 comment

0

You need to work with the damage of the weapon and see if the damage will be higher than the npc's current hp when the npc is shot.