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

Could Someone Help Fix This?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
local player = game.Players.LocalPlayer.Humanoid

if player then
    player.Humanoid.Health = 10
end

I've tried to get this to work, but it just won't. Anyone have any advice?

4 answers

Log in to vote
0
Answered by
Vathriel 510 Moderation Voter
9 years ago

The player does not have a humanoid; for this reason you must instead use the following: local player = game.Players.LocalPlayer.Character.Humanoid

local player = game.Players.LocalPlayer.Character:findFirstChild("Humanoid")
if player then
    player.Health = 10
else
end
0
Did not work. UltraTopher 0 — 9y
0
Oh. That didn't work either. Should I do. player.MaxHealth = 10? UltraTopher 0 — 9y
0
Make sure the script is in a local area, StarterGui for example, also make sure that you put a wait at the beginning incase the character has not fully loaded yet. Vathriel 510 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

Should I change it to:

    player.Humanoid.MaxHealth = 10
end

?

Log in to vote
0
Answered by 9 years ago
local player = game.Players.LocalPlayer.Character:findFirstChild("Humanoid")
if player then
    player.Health = 10
end

The one below will also work you just have to put it into a LocalScript and into StarterGui.

Log in to vote
0
Answered by 9 years ago

Put it in a LocalScript in StarterGui. LocalScripts can only go in players backpack or PlayerGui (PlayerGui = StarterGui) Scripts can't run LocalPlayer, only LocalScripts.

local player = game.Players.LocalPlayer.Humanoid

if player ~= nil then -- ~= means it's the opposite. So if it were to say = nil, that means if it is nil it will work, if it is ~= and Humanoid is nil, it won't work.
    player.Humanoid.Health = 10
end

Answer this question