I have a part inside of a model welded and inside of a starter character, and inside workspace, I have a damage script that's supposed to make the part deal damage. The problem is, it doesn't work. The part definately is touching other players, but it isn't dealing any damage. Here's the script.
local debounce = false local dmg = 27 function OnTouched(hit) if hit.StarterPlayer.StarterCharacter.saberlight.blade ~= nil then if debounce == false and hit.StarterPlayer.StarterCharacter.saberlight.blade:findFirstChild("Humanoid") ~= nil then debounce = true hit.StarterPlayer.StarterCharacter.saberlight.blade:findFirstChild("Humanoid"):TakeDamage(dmg) wait(1.2) debounce = false end end end script.Parent.Parent.StarterCharacter.saberlight.blade.Touched:connect(OnTouched)
I would recomend adding some print()
statements to check if everything works.
This is still your code and I have NOT fixed any evantual problems
local debounce = false local dmg = 27 function OnTouched(hit) print("Touched") if hit.StarterPlayer.StarterCharacter.saberlight.blade ~= nil then print("saberlight.blade") if debounce == false and hit.StarterPlayer.StarterCharacter.saberlight.blade:FindFirstChild("Humanoid") ~= nil then print("Humanoid found") debounce = true hit.StarterPlayer.StarterCharacter.saberlight.blade:FindFirstChild("Humanoid"):TakeDamage(dmg) wait(1.2) debounce = false end end end script.Parent.Parent.StarterCharacter.saberlight.blade.Touched:Connect(OnTouched)
If you see all the prints in the output I will try to understand where the problem lies.