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

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

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

3 comments

0

I'm guessing this is a free model?

2

http://wiki.roblox.com/index.php/API:Class/Humanoid - Simply Humanoid.Health and Humanoid.MaxHealth

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

1 answer

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)

2 comments

0

I really dont care, if its there i have the right to use it

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.

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