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

Script's object identification is glitched?

Asked by
drew1017 330 Moderation Voter
8 years ago
script.Parent.box.Touched:connect(function(hit)
    if hit and hit.Parent and hit.Parent:FindFirstChild'Humanoid' and hit.Parent.Humanoid:FindFirstChild'bullets' then
        print(hit.Parent.Name) -- Player1
        if hit.Parent:FindFirstChild'Humanoid' then
            print(hit.Parent.Humanoid.Name) -- Humanoid
        end
        if script.Parent.Type.Value == 'Health' and hit.Parent.Humanoid.Health < hit.Parent.Humanoid.MaxHealth then
            hit.Parent.Humanoid.Health = script.Parent.Humanoid.Health + 1.5
            script.Parent:Destroy()

The line that adds 1.5 health to the humanoid errors saying humanoid is not a valid member when it has already said it exists several times before, plain and simple. Help?

1 answer

Log in to vote
0
Answered by
Discern 1007 Moderation Voter
8 years ago

I'm assuming this is not the full script (like you didn't put the ends in your question). I just added the ends in there just in case.

You've accessed the humanoid as hit.Parent.Humanoid in all the lines before, and on the line in question, you have it as script.Parent.Humanoid. This is probably a syntax error and you accessed the wrong instance's parent.

Fixed Code:

script.Parent.box.Touched:connect(function(hit)
    if hit and hit.Parent and hit.Parent:FindFirstChild'Humanoid' and hit.Parent.Humanoid:FindFirstChild'bullets' then
        print(hit.Parent.Name) -- Player1
        if hit.Parent:FindFirstChild'Humanoid' then
            print(hit.Parent.Humanoid.Name) -- Humanoid
        end
        if script.Parent.Type.Value == 'Health' and hit.Parent.Humanoid.Health < hit.Parent.Humanoid.MaxHealth then
            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health + 1.5 --You had script.Parent.Humanoid.
            script.Parent:Destroy()
        end
    end
end)

If I helped you out, be sure to accept my answer!

0
pffpppt i was even aware of that before and i started fixing it lol drew1017 330 — 8y
Ad

Answer this question