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

The code is trying to call on WaitForChild rather than Humanoid, how do I fix this?

This is the error I'm getting and it brings me to line 3

WaitforChild is not a valid member of Model "Workspace.AlphaFlame5"

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Character:WaitforChild("Humanoid")

local PlrStats = Player:WaitForChild("PlrStats")

local Stamina = PlrStats:WaitForChild("Stamina")
local MaxStamina = PlrStats:WaitForChild("MaxStamina")
local Level = PlrStats:WaitForChild("Level")
local Exp = PlrStats:WaitForChild("EXP")

local PlrInfo = script.Parent
local HealthBar = PlrInfo.HealthBar
local StaminaBar = PlrInfo.StaminaBar

local HP_Display = PlrInfo:WaitForChild("HealthDisplay")
local STM_Display = PlrInfo:WaitForChild("StaminaDisplay")
local Lvl_Display = PlrInfo:WaitForChild("LvlDisplay")
local Exp_Display = PlrInfo:WaitForChild("ExpDisplay")

local runService = game:GetService("RunService")

runService.Heartbeat:Connect(function()
	HP_Display.Text = "HP:"..math.floor(Humanoid.Health).."/"..Humanoid.MaxHealth
	STM_Display.Text = "Stamina:"..Stamina.Value.."/"..MaxStamina.Value
	Lvl_Display.Text = "Lvl:"..Level.Value
	
	HealthBar.Size = UDim2.new((Humanoid.Health/Humanoid.MaxHealth)* 0.893,0,.0071,0)
	StaminaBar.Size = UDim2.new((Stamina.Value/MaxStamina.Value)* 0.895,0,.0071,0)
end)

2 answers

✓ Accepted answer

Lua is case sensitive, its just erroring because your wrote WaitforChild instead of WaitForChild. :)

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Character:WaitForChild("Humanoid")

local PlrStats = Player:WaitForChild("PlrStats")

local Stamina = PlrStats:WaitForChild("Stamina")
local MaxStamina = PlrStats:WaitForChild("MaxStamina")
local Level = PlrStats:WaitForChild("Level")
local Exp = PlrStats:WaitForChild("EXP")

local PlrInfo = script.Parent
local HealthBar = PlrInfo.HealthBar
local StaminaBar = PlrInfo.StaminaBar

local HP_Display = PlrInfo:WaitForChild("HealthDisplay")
local STM_Display = PlrInfo:WaitForChild("StaminaDisplay")
local Lvl_Display = PlrInfo:WaitForChild("LvlDisplay")
local Exp_Display = PlrInfo:WaitForChild("ExpDisplay")

local runService = game:GetService("RunService")

runService.Heartbeat:Connect(function()
	HP_Display.Text = "HP:"..math.floor(Humanoid.Health).."/"..Humanoid.MaxHealth
	STM_Display.Text = "Stamina:"..Stamina.Value.."/"..MaxStamina.Value
	Lvl_Display.Text = "Lvl:"..Level.Value

	HealthBar.Size = UDim2.new((Humanoid.Health/Humanoid.MaxHealth)* 0.893,0,.0071,0)
	StaminaBar.Size = UDim2.new((Stamina.Value/MaxStamina.Value)* 0.895,0,.0071,0)
end)

1 comment

0

Thank you so much, I have a tendency to look over small details like that often.

Lua is case sensitive and you entered WaitforChild() instead of WaitForChild() on line 3.

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