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

Script's object identification is glitched?

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

✓ Accepted answer

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!

1 comment

0

pffpppt i was even aware of that before and i started fixing it lol

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