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

Health Changer Script?

Asked by
22To 70
9 years ago

Well im basically trying to make a health changer to make the player get 300 health on start.

I'm new to this but this is what i tried.

OnEntered()
ChangeHealth.Humaniod.MaxHealth=300
3
That isn't Lua. You just typed random English characters into your script editor. Review your basics. Perci1 4988 — 9y
0
so u had to thumbs it down? jeez.... 22To 70 — 9y

1 answer

Log in to vote
2
Answered by 9 years ago

First off, onEntered isn't an actual function. We can use the event "PlayerAdded" to see if the player joins the game. Even then we need to use the "CharacterAdded" event. After that, we need to make the characters MAXHEALTH to 300. Not it's regular health. Then after that make the player's character's humanoid's health the same as its max health.


PlayerAdded is when a player joins the game.

game.Players.PlayerAdded:connect(function(player)
    print(player.Name) --If you join the game as builderman it will print "Builderman", if you join as another account then it would print that player's name.
end)

Now, CharacterAdded. This has a special feature. It waits until the character is finished loading. You don't even need a died event for this. Since characteradded does it all for you!

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        print(#character:GetChildren()) --Prints the number of bodyparts, hats, and etc all combined. It will also print again when a player respawns.
    end)
end)

Next we can change the MaxHealth.

--LocalScript
local player = game:GetService("Players").LocalPlayer
local character = player.Character
repeat wait() until character --wait until the character spawns.
character.Humanoid.MaxHealth = 300 --Changes his MaxHealth to 300.

That's pretty much it, except one problem. The player has 1/3 of his health missing! That's because while his max health is 300, they only have 100 health. So we just heal them as soon as they spawn.

--LocalScript
local player = game:GetService("Players").LocalPlayer
local character = player.Character
repeat wait() until character --wait until the character spawns.
character.Humanoid.MaxHealth = 300 --Changes his MaxHealth to 300.
character.Humanoid.Health = 300
--[[You can do it this way^ or this way
v]]
character.Health = character.Humanoid.MaxHealth

Now here's the finished product for regular and local scripts. Regular:

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        local h = character:FindFirstChild("Humanoid")
        if h then
            h.MaxHealth = 300
            h.Health = h.MaxHealth --or h.Health = 300
        end
    end)
end)

Local:

--LocalScript
local player = game:GetService("Players").LocalPlayer
local character = player.Character
repeat wait() until character --wait until the character spawns.
character.Humanoid.MaxHealth = 300
character.Humanoid.Health = character.Humanoid.MaxHealth --or h.Health = 300



Hope this helps!

0
Oh my, I just realised how long my answer is... Wow. EzraNehemiah_TF2 3552 — 9y
0
Its great now i understand..i always thought it was onEntered..thanks dude I know why my on entered scripts wasnt working 22To 70 — 9y
0
In your repeat loop, if the character is nil on line 3 the loop will wait forever. This is because the variable won't change, even if the property changes. Just define 'character' after the loop. Perci1 4988 — 9y
Ad

Answer this question