#How to make sure the sword script only gives one kill value after one kill

1 messages · Page 1 of 1 (latest)

wise salmon
#

This Script function activates every time the sword comes in contact with humanoid, at the end when the player dies it should only give one kill value but for some reason it randomly gives more.

wise salmon
#

if there is any info that is you guys need to help me let me know

vagrant hatch
#

Probably because
If ( humanoid.Health <= 0 ) then

#

Also u are using findFirstChild but F should be caps

#

The event can fire multiple times per a swing you might want to track recently hit targets

#

Try using Humanoid.Died

#

Instead

wise salmon
#

I'm not really sure how I can do that

steel tide
#

wait I don't understand what is your if block?

#

youre checking if health is lower than 0 and/or equal do you have any code that limits the health from dropping further?

stray wadiBOT
#

studio** You are now Level 1! **studio

steel tide
#

because the way I see it the health still drops

#

so it loops the kill

#

you should put the killvalue in another code that check if health drops below 1

stray wadiBOT
#

studio** You are now Level 2! **studio

steel tide
#

Or edit the code to make it so once the health drops below 1 stop damage from being taken any further and give a kill

vagrant hatch
#

I see several empty or misaligned end statements that may cause logic errors

steel tide
#

I dont see any end issues

vagrant hatch
#

Like if not rightArm then end

#

This doesn’t do anything

steel tide
#

maybe he doesn't know that he can insert end right after then instead of putting it below

#

no idea

#

Maybe he thinks if the if doesn't return true it exits the function?

vagrant hatch
#

U can make it return

steel tide
#

you right maybe we should tell him

vagrant hatch
#

Yeah

#

He would still need to track the target or add a cooldown on the hitbox

#

If he keeps having value errors

#

Probably because the event is firing multipletimes

steel tide
#

what you can do is check at the start of the function if health is lower than 0 if yes return end

wise salmon
steel tide
#

do it works tho?

wise salmon
#

Nope

#

Did not work

steel tide
#

or returns true if there 1 true

#

you need to put and

vagrant hatch
#

If rightArm then
End is what i see

#

Add a return inside then

wise salmon
#

Is because I closed it

steel tide
#

closed what?

wise salmon
#

The if statement

#

I just pressed the tiny arrow

steel tide
#

if rightArm then?

vagrant hatch
#

Ohhhh

#

Open the whole code and show us the numbers too

wise salmon
#

"if rightarn then return end"

steel tide
#

but what are you checking exactly with if rightArm?

wise salmon
#

My bad for not showing everything

vagrant hatch
#

Yeah what are u using it for

#

If u not using it. You could be causing logic errors

steel tide
#

are you trying to make it so if it hit right arm it doesn't inflict damage?

stray wadiBOT
#

studio** You are now Level 2! **studio

vagrant hatch
#

Send the code with everything rq

#

Just a screen shot

stray wadiBOT
#

studio** You are now Level 9! **studio

wise salmon
#

The right arm check is just to be sure the right arm before finding it's child right grip

wise salmon
vagrant hatch
#

Ok one second imma give it to my sister she knows how

#

Okay i know what the solution is

#

Actually before i tell u something more complicated lets test something first

#

On the line near the middle of the Blow function, where you return if the humanoid health is 0

#

You should try changing the comparator from == to <=

#

Bcs thats the condition ur checking to trigger an increase in kills

#

It needs a cooldown anyways between hits

steel tide
#

Theres more to that why do you have like 3 if statement that checks if user is dead?

#

you only need 1

wise salmon
#

Where is the third one?

vagrant hatch
#

Test out what i said first and if it doesn’t work we can try something more complicated

wise salmon
vagrant hatch
#

?

#

wdym?

wise salmon
#

I was before on a computer but now I'm in car

vagrant hatch
#

well theres a more concrete solution but I wanted to see if that would fix it

#

Just ping me when u get to the computer 😩

steel tide
vagrant hatch
#

its caused by the fact that multiple touches are occuring and so the event fires multiple times in an uncontrolled manner

wise salmon
vagrant hatch
#

it should check if the health is lower than or equal to 0 before inflicting damage in case the damage from a previous touch has lowered the health below 0, or else there may be a scenario where it may register an additional kill for touching an already-killed player. beacuse a negative is not equal to 0 so it wouldnt return.

#

u can use touched function

#

u just have to add a cooldowm

#

local cooling_down = false if cooling_down then return end cooling_down = true --run damage code task.wait(1)

#

cooling_down = false

#

also why do you check if rightarm exists? wouldnt the tool become unequipped automatically if the handle or the rightarm or the weld is destroyed?

#

Also why are you checking for if the sound is equal to nil?

wise salmon
wise salmon
#

Just to make sure of things

vagrant hatch
#

sound:Play(), is referencing the original (still nil) one — and it probably silently fails or errors does the sound work?

#

if sound == nil then
sound = Instance.new("Sound")
sound.Name = "GhostSound"
sound.SoundId = "rbxasset://sounds\HalloweenGhost.wav"
sound.Parent = script.Parent.Handle
end

wise salmon
#

The sound works

stray wadiBOT
#

studio** You are now Level 3! **studio

vagrant hatch
#

Ok nvm then

vagrant hatch
#

i also check everything though sometimes bcs it helps rule out potential causes of a bug to figure out the real cause lol

#

but u dont need to check for rightGrip, rightArm, or handle

wise salmon
#

To just not count the sword or item as humanoid part

wise salmon
#

@vagrant hatch this is my code I tried using the first way it didn't fix it same thing for the second way, I also tried to create a object as to force the script not to repeat with the same character

#

have I done any mistake?

#

and is there any thing I can do else?

#

NVM I'M STUPID

#

I CHANGED THE WORNG SCRIPT

#

the first way to fix it worked

vagrant hatch
#

Nice

wise salmon
#

Ty so much dude

#

I spent so much time trying everything to fix this script lol