I made a damaging part for a simple sword I made and it doesn't seem to work

I think that this should work for me, its just i suddenly get an error (dont even think its from the script changes)

Players.pap1io.Backpack.TestSword.LocalScript:6: attempt to index nil with ‘WaitForChild’

Well, I changed Char = LocalPlayer.Character to
Char = LocalPlayer:WaitForChild("Character"), and now it says that there is an infinite yield possible, which isn’t an error, but is still a warning.

It has worked however barely, the tool click works once and if i try again it just breaks.

That’s strange, it works fine for me.

What exactly is happening? Could you send the screenshots of your scripts?

image

What is the problem that happens?

robloxapp-20220706-2012395.wmv (2.9 MB)

sword doesnt have animation and just kills the npc when touched.

oh wow ofc the video didnt send

Are you looking for a slash animation to happen when you click it?

Yeah i am, should be working dk why it isnt

I fixed up my code from earlier. I didn’t know if you wanted to deal 10 damage every one second or be able to deal damage with no pause for one second (sorry for the confusing wording), so here is what I did if you wanted 10 damage every second:

In the main script, add a variable called otherval, and set it to false.

Add wait(1) and otherval = false into the last if statement (also you can just do if human instead of human ~= nil)

After the if hit:IsA("BasePart") then add if not otherval then and inside that indent otherval = true
Should look like this:

Basically the otherval acts as a debounce so it doesn’t automatically kill the NPC now.

Edit: Got the animation to work. Messed around with the script, and published the animation and used that ID. It didn’t work before I used that ID though, so maybe try re-publishing the animation and setting the owner to the animation as the same owner as the game if you haven’t already. Now for the script:

Delete the Humanoid, Player, and LocalPlayer variables. Now we should have the Char, Animation, AnimationTrack, and Tool variables.

Change the Char value to Tool.Parent, and the AnimationTrack value to Char.Humanoid:LoadAnimation(Animation)

Move the variables Char and AnimationTrack inside of the function before the AnimationTrack:Play()

Should look like this, except some of my variables have different names:

End result with the new code: (sorry I didn’t do the debounce thing the first time)

1 Like