Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you make part of a startercharacter deal damage?

Asked by
Lyphios 77
4 years ago

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)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

0
yes, it didn't print "humanoid found" in the output Lyphios 77 — 4y
0
But I did get an output that wrote script'Workspace.MyUsername.dmg1local', Line 20 Lyphios 77 — 4y
0
Can you tell me how you would go about doing this? Lyphios 77 — 4y
0
No I don't actually. I will try to understand but can't today I'm sorry, I might try tomorrow Spjureeedd 385 — 4y
Ad

Answer this question