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

Humanoid Is Not A Valid Member Of Workspace?

So I have this script inside my sword, and it seems to throw up an error when it touches anything other than a player, and I can't seem to find a way to make it still do damage to a humanoid if it touches something that doesn't contain a Humanoid

I've tried WaitForChild, but it throws up an infinite yield error

Av = 15 --Attack Value

tool = script.Parent

function tagHumanoid(humanoid,killer)
	
	if humanoid and killer then
		
		local tag = Instance.new("ObjectValue")
		tag.Name = "creator"
		tag.Value = killer
		tag.Parent = humanoid
	end
	
end

script.Parent.Handle.blade.Touched:connect(function(p)
	
local plr = game.Players:GetPlayerFromCharacter(tool.Parent)

if script.Parent.CanDamage.Value == true then

	script.Parent.CanDamage.Value = false
	
	local humanoid = p:FindFirstChild("Humanoid")

	p.Parent.humanoid:TakeDamage(Av)
	
	tagHumanoid(humanoid, plr)

	wait(1)

	script.Parent.CanDamage.Value = true

	if p.Parent.Humanoid.Health < 1 then
		print("Player Has Died")
	end

	end

end)

1 answer

✓ Accepted answer

You dont check if what it touches is a player so if it isnt a player it trys to find a thing u would only find in a player

Av = 15 --Attack Value

tool = script.Parent

function tagHumanoid(humanoid,killer)

    if humanoid and killer then

        local tag = Instance.new("ObjectValue")
        tag.Name = "creator"
        tag.Value = killer
        tag.Parent = humanoid
    end

end

script.Parent.Handle.blade.Touched:connect(function(p)

local plr = game.Players:GetPlayerFromCharacter(tool.Parent)

if script.Parent.CanDamage.Value == true and p.Parent:FindFirstChild("Humanoid") then -- checking if its a player

    script.Parent.CanDamage.Value = false

    local humanoid = p.Parent:FindFirstChild("Humanoid")

    humanoid:TakeDamage(Av)

    tagHumanoid(humanoid, plr)

    wait(1)

    script.Parent.CanDamage.Value = true

    if p.Parent.Humanoid.Health < 1 then
        print("Player Has Died")
    end

    end

end)

7 comments

0

Now the script won't do damage to the player!?

0

It doesnt?

0

It doesn't throw up the "Humanoid Is Not A Valid Member Of Workspace" error, but it doesn't deal damage anymore

0

now?

0

it works, thx!

0

Can u accept the answer pls?

0

o, my bad forgot to do that lol

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