Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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
)

1 comment

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") ?

1 answer

✓ Accepted answer

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.

1 comment

0

Hehe,sorry for my gramatical errors,but it is good that i helped!

This discussion is preserved as it was. New answers, comments, and votes are closed.