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

Humanoid Is Not A Valid Member Of Workspace?

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
1
Answered by
IcyMizu 122
4 years ago
Edited 4 years ago

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)
0
Now the script won't do damage to the player!? Jomeliter 55 — 4y
0
It doesnt? IcyMizu 122 — 4y
0
It doesn't throw up the "Humanoid Is Not A Valid Member Of Workspace" error, but it doesn't deal damage anymore Jomeliter 55 — 4y
0
now? IcyMizu 122 — 4y
View all comments (3 more)
0
it works, thx! Jomeliter 55 — 4y
0
Can u accept the answer pls? IcyMizu 122 — 4y
0
o, my bad forgot to do that lol Jomeliter 55 — 4y
Ad

Answer this question