Hello, I have this problem with the error. Idk why it says that because its a variable.
20:03:11.873 Workspace.OzeanSyler.HealthbarServerSetup:16: attempt to index nil with 'FindFirstChild' - Server - HealthbarServerSetup:16
20:03:11.873 Stack Begin - Studio
20:03:11.873 Script 'Workspace.OzeanSyler.HealthbarServerSetup', Line 16 - Studio - HealthbarServerSetup:16
20:03:11.873 Stack End - Studio
and this is the script until line 16:
if script.Parent.Parent == "NowPlates" then
script:Destroy()
end
local Players = game:GetService("Players")
local Char = script.Parent
local Plr = Players:GetPlayerFromCharacter(Char)
local Humanoid = Char:FindFirstChild("Humanoid")
local Head = Char:FindFirstChild("Head")
local Healthbar = script:FindFirstChild("HealthBarGui")
local Container = Healthbar:FindFirstChild("HealthBarContainer")
does anyone know how to fix it?
any help is appreciated!
Use :WaitForChild() instead of FindFirstChild().
My assumption here would be that the FindFirstChild() returned nil because your object didn’t have time to load yet. WaitForChild() will wait (indefinitely) until your object is added.
Please let me know if this worked !
local Humanoid = Char:FindFirstChild("Humanoid")
local Head = Char:FindFirstChild("Head")
local Healthbar = script:FindFirstChild("HealthBarGui")
local Container = Healthbar:FindFirstChild("HealthBarContainer")
Or only one ? I would recommend you change all of these to WaitForChild()