Hello again Developers. I’m trying to make a button to give the player infinite health so that players can’t kill the player while shopping. Is there a way where I can make the player get infinite health?
– papahetfan
Hello again Developers. I’m trying to make a button to give the player infinite health so that players can’t kill the player while shopping. Is there a way where I can make the player get infinite health?
– papahetfan
I read this from another post so its not my idea but can help you. You create an invisible force field around the player:
local ff = Instance.new("ForceField")
ff.Parent = plrchar -- Add it to their character.
ff.Visible = false -- makes it invisible so it just seems like they are invincible.
Credit: @synical4
-- LocalScript
local player = game:GetService("Players").LocalPlayer
local char = player.Character
char:WaitForChild("Humanoid").Health = math.huge
Instead of a force field around the player (just doesn’t look right) this sets the player’s health to math.huge
which is infinite in Lua.
Remove collision also.
Exploiter can upwrite health like killblick object does.
Thats why the script sets it to visible false.
Also setting player health to math.huge wont help unless you set the players max health to math.huge too.
Thats true, how can i fix that problem?
Thank you for helping me! I also changed it for MaxHealth too.
I may not have had you as a solution but I did add your ForceField script to help too.
I know its fixed but
local function MakeInvicible(hum : Humanoid)
hum:SetStateEnabled(Enum.HumanoidStateType.Dead,false)
hum.BreakJointsOnDeath = false
hum.MaxHealth = math.huge
hum.Health = hum.MaxHealth
hum.HealthChanged:Connect(function() hum.Health = hum.MaxHealth end)
end
This make sure if something sets the health to 0 it wont die
OK, now is there a way where the player closes the shop off, it can go back to its normal health?
Yes, just do this:
-- LocalScript
script.Parent.MouseButton1Down:Connect(function()
local player = game:GetService("Players").LocalPlayer
local char = player.Character
char:WaitForChild("Humanoid").Health = 100
char:WaitForChild("Humanoid").MaxHealth = 100
end)
You’re still adding a new instance to a character, can be costly for performance on some low-end devices, like an old iPhone or iPad. Also just adding more random clutter to the explorer.
Adding onto what @2jammers said:
--Add in local script
local player = game:GetService("Players").LocalPlayer
local char = player.Character
local custom = math.huge
local default = 100
local customHealth = false
"Insert Button Location Here".Activated:Connect(function()
if customHealth == false then
char:WaitForChild("Humanoid").Health = custom
char:WaitForChild("Humanoid").MaxHealth = custom
else
char:WaitForChild("Humanoid").Health = default
char:WaitForChild("Humanoid").MaxHealth = default
end
end)
You guys are solving issue which can be simply avoided by using ForceField
.
Using ForceField
is better because it quite literally mitigates ANY health changes…
By doing math.huge
If player gets any damage player will have their healthbar shown… It is just better to use forcefield.