soo recently ive made a script where it prevent the player to die from any type of - health
i put the script on starterplaterscript as local script
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
humanoid.Health = 1000000
humanoid.MaxHealth = 1000000
does anyone know whats wrong with my script?
or maybe y know any other way to make the player cant died by other players/ using value to a part that cant damage the localplayer
You put it in a local script so the health isnt changed on the server. Also the player can still die it will just take a million damage. Also. you should edit maxhealth before health i believe
What @svenska_kartongbit said is correct, but I’ll try to explain what you’ll need to do to fix your problem:
Create a server Script, and place it inside of StarterCharacterScripts. You can optionally rename this Script to Health to overwrite the default health script, since its logic is no longer needed
This will need to be the code for the Script:
local humanoid = script.Parent.Humanoid
humanoid.MaxHealth = math.huge
humanoid.Health = math.huge
Note that I’m using math.huge. math.huge is a number value which is equivalent to infinity, which is the largest possible number. This means even if you deal a million damage to the Humanoid (or even a billion or more!), they’ll still stay alive
NPCs will still be able to get hurt unless you add the script to their character, since scripts placed inside of StarterCharacterScripts will only affect characters controlled by players
If you require killbricks to still be able to hurt player characters, then setting their health to infinity is not the ideal solution. You as the game dev have control over whether/how players are able to hurt each other, so if for example you wish to add a cosmetic sword to your game, you can code it to only swing but not damage other players, which will achieve the same result as setting their health to infinity
@AamTum This should still be able to kill players if they touch a killbrick, even if their health is infinity:
local killbrick = script.Parent
killbrick.Touched:Connect(function(otherPart)
local model = otherPart:FindFirstAncestorOfClass("Model")
if model then
local humanoid = model:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
end)
It will need to be a server Script that’s inside of the killbrick Part