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

My script for damaging on my sword is getting an error, How do I fix this?

Asked by 4 years ago

I made a sword that consists of 2 scripts, the damage and the main script.This happens when I hit the dummy and then hit away from the dummy. This is the error I am getting: https://prnt.sc/s4wr1p

Here is the damage script

local db = false
script.Parent.Handle.Touched:Connect(
    function(hit)
        if db == false then
            if hit.Parent.Humanoid then
                db = true
                hit.Parent.Humanoid:TakeDamage(10)
                script.parent.blood.PlaybackSpeed = math.random(1.0, 1.2)
                script.parent.blood:Play()
                wait(.5)
                db = false
                script.Disabled = true
            else
                return
            end
        end
    end
)

0
It says humanoid is not a valid member of workspace. In either line 5 or 7, hit.Parent is referring to Workspace. If hit is the player/entity, maybe try hit:FindFirstChild("Humanoid") ? awesomesauce905 4 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

You need to check first if the thing the sword is touching is an humanoid (an dummy or person) Here is what i mean:

local db = false
    script.Parent.Handle.Touched:Connect(
        function(hit)
            if db == false then
                   local human = hit.Parent:FindFirstChild("Humanoid")
                if human then
                    db = true
                    human:TakeDamage(10)
                    script.parent.blood.PlaybackSpeed = math.random(1.0, 1.2)
                    script.parent.blood:Play()
                    wait(.5)
                    db = false
                    script.Disabled = true
                else
                    return
                end
            end
        end
    )

Tell me if something is wrong here Hope it helped.

0
Hehe,sorry for my gramatical errors,but it is good that i helped! trustydoggy 24 — 4y
Ad

Answer this question