Ad
Log in to vote
0

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

Asked by 3 days ago

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

Log in to vote
1
Answered by 3 days ago

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)
0
Thank you so much, I have a tendency to look over small details like that often. AlphaFlame5 -1 — 3d
Ad
Log in to vote
0
Answered by
FrindowYT 283 Moderation Voter
2 days ago

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

Answer this question