Need help on kill detection/increase

So I am making a game I the players would be given a task to kill npc’s.

I made a script for the detection but the problem is that my sword has 4 skills.
Works perfect but not for one of the 4 skills.

My skill uses 20 parts which touch on the NPC’s body it will lose health.
-5 health per part.

I used this script to to add the the kills to the leaderstats.

if V1.Humanoid.Health < 1 then
	player.leaderstats.Kills.Value = player.leaderstats.Kills.Value + 1
	  if c:FindFirstChild("KilledNinjas") then
		c.KilledNinjas.Value = c.KilledNinjas.Value + 0.05
	  end
end

Usually i should be one but here there are 20 parts so they add up to 20 kills.
I debugged a lot for this.
So I changed the 1(on the 2nd line) to 0.05(that mean 0.05 * 20 = 1).

I thought it would work but nope. After I debugged a lot for this too I found our that you can’t used decimal numbers for IntValue’s and NumberValue’s.

So I switched to StringValues to check if it works but there to Nope

What can I do here?

Instead of this I suggest using Humanoid.Died

Thanks for helping but I don’t how to detect if the NPC was killed by a player with a sword using the skill.

I found out that by using

math.floor(x * 1)/1

Just need to calculate the perfect one

Yeah that’s a good idea, plus you should also use Collection services to tag the sword being used to know who killed who.

You can tag humanoids as ninjas and the sword being used with the players name.

https://developer.roblox.com/en-us/api-reference/class/CollectionService

Here is a tutorial that should help as well.

2 Likes

Hey thanks but do you know about math.floor?

math.floor basically rounds a number to the smaller integer of a given number.

Basically:

print(math.floor(3.456))

--// output: 3

Not really, but I can search it up on the dev api reference quite quickly

int math.floor ( number x )
Returns the largest integer smaller than or equal to x.

So basically in simple terms, it throws away the decimal of a number

  1. math.floor(1.7) = 1

  2. math.floor(1.1) = 1

Simple testing in the console should prove this true

Output in the command console.

> print(math.floor(1.1))
1
> print(math.floor(1.7))
1

There is also math.ceil, which has a similar function, but instead of rounding to the smaller integer, rounds to the bigger

print(math.floor(1.3))

--// 1

print(math.ceil(1.3))

--// 2

Here is how I would do it :
first: I would give the plr a invisible value inside the Humanoid called Tag – that gets inside plr if hit with sword.
Tag is a objectvalue , Tag.Value = plr
Humanoid.Died:connect(function()
if Humanoid:findFirstChild(“Tag”) then
Tag.Value.KilledNinjas.value = …
end

theres a function called math.round(valuehere)
it isn’t documented by roblox but works.

Yeah, but as I saw so far, that function takes more resources than rounding by yourself a number using math.floor.

math.floor rounds to the nearest smallest integer, but I believe math.round would do something like this:

math.floor(x+0.5)

So if its 1.9, it gets rounded to 2, and if its 1.4 it gets rounded off to 1