like I hold a button down and I ether take less or no damage. Can anyone help me with that?
COMMUNITY QUESTION
how do i make a block script that makes you take less or no dammage?
1 answer
Making a no damage script would be easy, since all you would need to do is create an invisible ForceField.
However if you would want to make weapons deal less damage to you, the best solution would be to modify their scripts directly.
Although you can still do something like my example below, it won't prevent you from dying if the damage sets your hp to 0.
local plr = game:GetService("Players").LocalPlayer
local takeLessDmg = false
game:GetService("UserInputService").InputBegan:Connect(function(iobj, gp)
if gp then return end
if iobj.KeyCode == Enum.KeyCode.Z then --an example
takeLessDmg = true
end
end)
game:GetService("UserInputService").InputEnded:Connect(function(iobj, gp)
if gp then return end
if iobj.KeyCode == Enum.KeyCode.Z then --an example
takeLessDmg = false
end
end)
local char = plr.Character
local function CharAdded(char)
local hum = char:WaitForChild("Humanoid")
local hpBefore = hum.Health
hum.HealthChanged:Connect(function(hp)
local damageTaken = hpBefore - hp
if damageTaken <= 0 then--if healed and not damaged
hpBefore = hp
return
end
if not takeLessDmg then
hpBefore = hp
return
end
hum.Health = hum.Health + damageTaken / 2 --take 1/2 of the damage
hpBefore = hum.Health
end)
end
plr.CharacterAdded:Connect(CharAdded)
if char then
CharAdded(char) --in case the script missed the first CharacterAdded event
end
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
THIS IS NOT A WEBSITE FOR YOU TO ASK FOR SCRIPTS
...
geesh...
THIS IS NOT A REQUEST SITE!!! Show your script at least
Calm down guys, he's just asking for the idea on how to do that, I think. And even if not, you don't have to use capslock /shrug