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

Workspace has a child "Player1" which has a child "Humanoid" , so why does output return f as nil?

f = game.Workspace:FindFirstChild("Humanoid",true)
if f.Parent.Name == "Player1" then
while true do
if f.Health <= 99 then
f.Health = f.Health + 1
wait(.01)
end
end
end

A very simple script to heal me when injured rapidly during Edit on ROBLOX, yet I can't fathom why f can't be found.

2 comments

1

One line one, the players spawns after the script runs. A simple fix would be adding like a wait(1) at the beginning of the script, but I would suggest using the player added event instead.

0

That helped, thank you. Now I must simply incorporate a loop into Player Added :/

1 answer

✓ Accepted answer

A easy solution would be to use a local script in the StarterPack.

local player = game.Players.LocalPlayer -- Get's the player.
local playerhumanoid  = player.Character.Humanoid  -- Do not need to put wait() because in edit, the character loads instantly, added in humanoid with this variable to condense the script.

playerhumanoid.HealthChanged:connect(function()
if playerhumanoid.Health < 99 then
playerhumanoid.Health = playerhumanoid.Health + 1 -- We do not need keep calling on the function manually, it will call itself wen it adds health back
wait()
end)

There might be a few errors in there, let me know if there are and I will fix them.

2 comments

0

Thanks, the conditional function was what I was missing.

0

Happy to help. :)

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