Why is this simple damage script not working?

I’ve been trying to make this sword work, and I’ve now reduced it to the simplest form of a damage script, and not even the sound is playing. My test dummies are npcs, the sword is uncontrollable, please help.

	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent:FindFirstChild("Humanoid"):TakeDamage(10,50)
		script.Parent.Parent.Parent.Hit:Play()
	end
end)

Take damage only accepts one argument, if you want random use math.random:

hit.Parent:FindFirstChild("Humanoid"):TakeDamage(math.random(10,50))
1 Like

still does not work…

script.Parent.Handle.Blade.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent:FindFirstChild("Humanoid"):TakeDamage(math/Random(10,50))
		script.Parent.Parent.Parent.Hit:Play()
	end
end)

even if i remove the damage part the sound does not play…

blade is a mesh, could that be it?

its math.random, not math/random

1 Like

If it’s a SpecialMesh, not a MeshPart, that’d be an issue. Check the error log to see if there’s any errors, that’ll give you more context on what’s erroring. It’s probably the math/Random thing, but there could be other errors too. (You should at least do the bare minimum to try and debug before coming back to say it doesn’t work.)

3 Likes

it is a mesh part, and ive fixed the math/Random… and ive been trying to debug for months now

Try:

              ''''
             script.Parent.Handle.Blade.Touched:Connect(function(player)
                 if hit.Parent == player then 
                      player:FindFirstChild("Humanoid"):TakeDamage(math.random(10,50))
                      print(TakeDamage)
                 end
             end)
                           '''

Correct me if I’m wrong…

few errors in ur script:

script.Parent.Handle.Blade.Touched:Connect(function(hit)
	if hit.Parent then
		hit.Parent:FindFirstChild("Humanoid"):TakeDamage(math.random(10,50))
		print("TakeDamage")
	end
end)

Here I edited my script, check again

That would not work.

What is player? You don’t define it anywhere. This is essentially checking if hit.Parent is nil, which doesn’t make sense if it triggered the Touched event.

This is misuse of FindFirstChild and is no better than player.Humanoid.

What are you trying to do here?? TakeDamage isn’t a defined variable, this’ll just print nil.

You never close the opening parenthesis for the :Connect function.

3 Likes

I corrected my script, but thanks for letting me know!

This is regarding the current version.

1 Like

I think this would work!

script.Parent.Handle.Blade.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid:TakeDamage(math.random(10, 50))
		script.Parent.Parent.Parent.Hit:Play()
	end
end)
      ''''
         script.Parent.Handle.Blade.Touched:Connect(function(player)
             if hit.Parent == player then 
                  player:FindFirstChild("Humanoid"):TakeDamage(math.random(10,50))
                  script.Parent.Parent.Parent.Hit:Play()
             end
         end)
                       '''

did not work…

Why print(TakeDamage), it ain’t a varaible.

1 Like

Did you check the output for errors? Are you sure the script is even running? It’s hard to say what’s wrong when you aren’t doing anything to try and debug.

3 Likes

Is there any errors in output?

why do you have a part within a part?

no errors…