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

How could I Make a Player Take Half Damage?

I believe there are many different ways to do this, but I'm not sure which is easiest. Would it be easy enough to simple double a players max and current health then half it when I want them to take health normally again?

3 answers

player = game.Players.LocalPlayer
character = player.Character or player.CharacterAdded:Wait()
hum = character:WaitForChild("Humanoid")
health = 100

hum.Changed:Connect(function() --this fires when a property of the players humanoid changes
	if hum.Health ~= health then
		a = health - hum.Health
		hum.Health = math.floor((health - a) + .5) --this rounds the health to an integer
		health = hum.Health
	end
end)

Untested, but this is the general idea.

1 comment

0

This didn't work. I tried doing what I mentioned earlier and it works fine except when dividing the health by 2 at the end, it makes it look like you got hurt even though you didn't really.

The easiest way I've found of doing this sadly requires you to adjust your actual attack scripts themselves. Here's a quick example.

--WARNING: This script is not fully functional as it will be missing key pieces like debounces. This is purely on how to handle the damage calculation.
if part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hitplayer = hit.Parent
	else if hit.Parent.Parent:FindFirstChild("Humanoid") then
		hitplayer = hit.Parent.Parent
		end
	end

	local dam = 10

	if hitplayer:FindFirstChild("Armor") then
		dam = math.floor(dam * .5) 
	end
	
	hitplayer.Humanoid.Health = hitplayer.Humanoid.Health - dam
end

So whenever you want the player to only take half damage, you'd insert an object, I use stringvalues, and rename it to something for your damage script to check, in the example, Armor.

Outside of this I've found no successful way to do this. Maybe if someone more experienced wants to swoop in on this one but for now this is a method that I guarantee will work.

1 comment

0

Feel free to suggest changes then. Not the most experienced scripter so my work is going to be rough.

I don't know if you want it to damage on touch or whatever, but If you're just looking to simply make the player lose half their current health then you could use this:

Humanoid:TakeDamage(Humanoid.Health/2) 
--change .Health/2 to .MaxHealth/2 if you want them to lose half their health

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