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

Why is, "Humanoid is not a valid member of Backpack"?

Hi!

In my healing script, there is a part where you heal 25 times in quick succession gaining 1 health point each time. But whenever you deselect, sometimes it breaks, as the took goes back into the backpack, how could I fix this?

By the way this is where the script is located

StarterPack.MedKit.Script

 			for i = 1,25 do
					if script.Parent.Parent.Humanoid.Health ~= 100 or script.Parent.Parent.Parent.Parent.Humanoid.Health ~= 100 then

					Health:TakeDamage(-1)
					print('Health added = ' , i )
					wait(.1)
					print("Hi")
				end
			
			end
		end

i've also tried

					if script.Parent.Parent.Humanoid.Health ~= 100 or script.Parent.Parent.Parent.Humanoid.Health ~= 100 then

All help obliged, thanks!

1 answer

✓ Accepted answer

The player's humanoid is in their Character, therefore to access the humanoid, you need to access the character.

whenever you have access to the Character, you can access the Character by doing Player.Character, if Player.Character is nil then you'll have to wait for when the player's character is available by doing local character = Player.CharacterAdded:Wait().

in a localscript, you can access the Player object by doing local player = game.Players.LocalPlayer..

i recommend accessing the player's character by doing local character = player.Character instead of using script.Parents as they can quickly get ugly

for instance:

in a localscript

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait();
local humanoid  = character:WaitForChild("Humanoid")

2 comments

0

Would the server script alternative be: local players = game:GetService("Players") // players.PlayerAdded:Connect(function(player) // local character = player.CharacterAdded:Wait() // end)

1

game:GetService is just used to get the Roblox Service Class, so it can be used anywhere... Object.EventName:Connect(f) is the syntax to listen for when an event Occurs on an object.. all event classes have a Wait() method which you can call to halt the code until that event fires.. so if i did game.Players.PlayerAdded:Wait() in a server script, it would halt the code until a player joins game

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