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

How do I create a script that sets a players Health?

Asked by 6 years ago

I have a script that sets a players Max Heatlh but I need help creating a script that sets the players Health

Here is My Max Health Script

wait()
local character = game.Workspace:FindFirstChild(script.Parent.Parent.Name)

if script.Parent.Parent:FindFirstChild("Values") == nil then
    value = Instance.new("NumberValue")
    value.Name = "Values"
    maxhealth = Instance.new("NumberValue")
    maxhealth.Name = "MaxHealth"
    maxhealth.Parent = value
    maxhealth.Value = 250
    value.Parent = script.Parent.Parent
end


addscript = script.SetMaxHealth:Clone()
addscript.Parent = character
addscript.Disabled = false

Second Script

h = script.Parent.Humanoid

while true do
    h.MaxHealth = game.Players:FindFirstChild(h.Parent.Name).Values.MaxHealth.Value
    wait(2)
    end
0
I'm guessing this is a free model? MRbraveDragon 374 — 6y
2
http://wiki.roblox.com/index.php/API:Class/Humanoid - Simply Humanoid.Health and Humanoid.MaxHealth MooMooThalahlah 421 — 6y
0
I hate when people link me to the wiki and dosen't explain what i should be looking at. Also that didn't do anything 1freshkidz1 12 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Probably should go watch some tutorials and get some understanding of how programming/scripting works in roblox before frankensteining scripts.

--LocalScript
local ply = game.Players.LocalPlayer    --This is the player which has the gui, backpack, etc
local val = 200 --Value we want for the player's maxhealth

ply.CharacterAdded:connect(function(cha)    --Connecting event to function to get the player character
    local hum = cha:WaitForChild("Humanoid")    --Waiting for character's humanoid child
    hum.MaxHealth = val --Humanoid's MaxHealth and Health properties aren't objects, but number's so you don't use Value for them
    hum.Health = val
end)
0
I really dont care, if its there i have the right to use it 1freshkidz1 12 — 6y
0
You do have the right to use it, but you should probably try to understand how things work in the engine so the site isn't flooded by stupidly simple questions. Meltdown81 309 — 6y
Ad

Answer this question