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

How would I change this to make the Humanoid lose a random amount of health?

Hi, at the moment this script will work but when my character touches the brick it sometimes loses health or gains health. I have tried making the numbers both negative but that just errors. So, I would appreciate it if anyone could help me with this?

script.Parent.Touched: connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid ~= nil and humanoid.Health > 0 then
		local f = Instance.new("Fire", hit.Parent)
		f.Color = Color3.new(0, 85, 255)
		humanoid.Health = math.random(35, 100)
		
	end

end)

2 answers

✓ Accepted answer

You would have to subtract their health:

humanoid.Health = humanoid.Health - math.random(1, humanoid.Health)

Subtracting their health guarantees that they take damage.

2 comments

0

This also never fails as the Health property keeps changing.

0

Thank you very much I don't know why I didnt think of that!

Make the humanoid take damage

humanoid:TakeDamage(math.random(35,100))

3 comments

0

^ No

0

The health would then bug out and you would get an error.

0

Well the health value would change, it's not always 100, it's an unknown number when you're scripting it(not playing), so you should throw in a variable

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