This is my script that keeps giving me the error this error 09:30:35.247 - Workspace.protectiverobos.Up.LocalScript:3: attempt to call method 'FindFirstChild' (a nil value)
local player = game.Players.LocalPlayer local name = game.Players.LocalPlayer.Name local gethumanoid = game.workspace.name:FindFirstChild("Humanoid") while true do wait() if gethumanoid.Health <= game.ServerStorage.PlayerStats.NeededHealth then script.Parent.Value = false end end
You can get the player's Character from Player.Character and from there you can either use char.Humanoid
or char:FindFirstChild("Humanoid")
or char:WaitForChild("Humanoid") which I used below.
EDIT: For your new error, I have created a new local variable to get the ServerStorage
service and wait for PlayerStats
to load in.
local player = game.Players.LocalPlayer local char = player.Character -- replaced 'name' variable local gethumanoid = char:WaitForChild("Humanoid") -- WaitForChild is used to prevent any errors local plrStats = game:GetService("ServerStorage"):WaitForChild("PlayerStats") -- Created this variable to wait for the PlayerStats to load in to (hopefully) prevent any errors while true do wait() if gethumanoid.Health <= plrStats.NeededHealth then script.Parent.Value = false end end
You're accessing the humanoid wrong. You're trying to find it within the workspace name, this is incorrect. Try this instead:
local player = game.Players.LocalPlayer local humanoid = player.Character:FindFirstChild('Humanoid')