Weird studio/scripting bug

Hello! I have recently have gotten a issue where when my weapon tool kills someone it gives 3 kills when I have it said to give only give 1 kill. Here is some of the code

Sorry for the bad code

please for the love of eyesight keep your variable names reasonable
like deathConn
etc

And let alone no need to disconnect or anything just do it normally and use :Once
e.Parent.Humanoid.Died:Once …

And may I see the rest of the code if you insist on doing the connect way? because the only difference is connect will fire everytime unless it’s disconnected
Once only fires once and no other times.

1 Like

I need to work on cleaning my code lol

Here is the whole code

assumption 1 is that your main remote is being fired over and over
do basic debugging
print()
print when the remote is fired
print when the hitbox is touched
print when the humanoid died!

In my other script that fires the event it has a cooldown set so that should not be the problem, And when I checked on printing
image
Event fired is when the enemy dies, It fired 3 times.

send the code again please with the added prints.

Here you go

You would need to use :Once() on your Died function:

if not killed then
    killed = true
    gggfgrgsgr = e.Parent.Humanoid.Died:Once(function()
        print("Event Fired")
        plr.TemporaryStats.Kills.Value += 1
        gggfgrgsgr:Disconnect()
    end)
end

Try this

script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr, damage, currentm1)
	local playerCharacter = plr.Character
	if not playerCharacter then return end
	
	local humanoidRootPart = playerCharacter:FindFirstChild("HumanoidRootPart")
	local punchAnimation = script.Punch
	
	local hitbox = Instance.new("Part")
	hitbox.Size = Vector3.new(6, 6, 6)
	hitbox.Name = "Hitbox"
	hitbox.Transparency = 1
	hitbox.CanCollide = false
	hitbox.CFrame = humanoidRootPart.CFrame
	
	local params = OverlapParams.new()
	params.FilterType = Enum.RaycastFilterType.Exclude
	params.FilterDescendantsInstances = {playerCharacter}
	
	local result = workspace:GetPartBoundsInBox(hitbox.CFrame, hitbox.Size)
	if result then
		for _, obj in result do
			local character = obj:FindFirstAncestorWhichIsA("Model")
			if not character then continue end
			
			local humanoid = character:FindFirstChildWhichIsA("Humanoid")
			if not humanoid or humanoid.Health <= 0 then continue end
			
			humanoid.Died:Once(function()
				local temporaryStats = plr:FindFirstChild("TemporaryStats")
				local kills = temporaryStats:FindFirstChild("Kills")
				kills.Value += 1
			end)
			
			humanoid:TakeDamage(damage)
			punchAnimation:Play()
		end
	end
	
	task.delay(0.3, function()
		hitbox:Destroy()
	end)
end)

Both the two above me are correct, touched is unreliable most of the time, using result is better as touched fires MULTIPLE times.

I tried this and it just killed the player. But thanks for the help!

Still the same result, But thanks for the help!

Both of them for me did not work sadly, But thanks for the help!

shouldn’t you also disconnect the touched event after a certain period of time has passed without anyone touching the hitbox?

and i think what should be the best way to award the Kill is by checking if the enemy’s humanoid’s health is less than or is equals to 0 as to use .Died

example:

Hum:TakeDamage(damage)

if Hum.Health <= 0 then
      if not killed then
              killed = true
              Kills.Value += 1
       end
end