As the title suggest, I am making a debug menu and my first button is to make the player invulnerable to all sources of damage.
I have tried giving the player a force field, however when I place a part that takes away the players health it still damages and kills the player.
Additionally I have tried simply setting the player health really big and constantly restoring the health, however that means the script will run constantly and I want to find an alternative.
local character = player.Character
function pressed ()
local FF = Instance.new("ForceField", character)
end
invulnButton.MouseButton1Click:Connect(pressed)
After some research I found out the force field may only act as a way to prevent the player from exploding.
So what alternative should I use to prevent any damage being given?
What i meant was the player would take damage and would not get it restored (since the player regen is disabled for game play) without using a loop function.
For example:
while bigHealth == true do
Player.Humanoid.Health == max
wait(however long)
end
I would prefer not need to call back to this script at all in this regard.
Disable the humanoid dead state? Also, forcefields only negates damage through Humanoid:TakeDamage, so it won’t prevent damage that manipulates the health directly.
Are you creating the forcefield on the server or the client? From the first post it seems you are creating it from the client. You should fire a remote and create the forcefield on the server.
Because the part damages from the server it cannot see the locally created forcefield.
Just use the HealthChanged event on Humanoid, if you want the health to floor on 1.
Humanoid.HealthChanged:Connect(function(health)
if health < 1 then
Humanoid.Health = 1
end
end)
-- or permanent
Humanoid.HealthChanged:Connect(function()
Humanoid.Health = 100 -- or Humanoid.MaxHealth
end)
ForceField is optional, and it can toggle visibility.
I almost forgot to ask, is this done through a server script? If not, do that. In order to work with it from a LocalScript, proceed firing a RemoteEvent.