Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 8 years ago
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.

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. User#11440 120 — 8y
0
That helped, thank you. Now I must simply incorporate a loop into Player Added :/ pmcdonough 85 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

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.

0
Thanks, the conditional function was what I was missing. pmcdonough 85 — 8y
0
Happy to help. :) UltChowsk 85 — 8y
Ad

Answer this question