I’m trying to check to see if the value
of the player’s life is infinite, any solution?
--LOCAL SCRIPT:
local health = game.ReplicatedStorage.health
local player = game.Players.LocalPlayer
local maxHealth = player.Character:WaitForChild("Humanoid").MaxHealth
health.Changed:Connect(function()
if maxHealth == math.huge then
print("Infinity")
end
end)
the command print… nothing…
Of course it doesn’t print anything because you’re checking it on a local script, exploiters can just remove this local script and have inf life. Do the checking on server script.
1 Like
You are not checking if the health of the player is changing, you are checking if health in ReplicatedStorage is changing.
Additionally, maxHealth is a number, not a table or Instance, so if player.Character:WaitForChild(“Humanoid”).MaxHealth changes then maxHealth will not change
here is new code that might work
--LOCAL SCRIPT:
--old code
--local health = game.ReplicatedStorage.health
local player = game.Players.LocalPlayer
--old code
--local maxHealth = player.Character:WaitForChild("Humanoid").MaxHealth
--new code
local humanoid = player.Character:WaitForChild("Humanoid")
humanoid.Changed:Connect(function(property)
--extra code to check if MaxHealth changed and not something else
if property == "MaxHealth" then
if humanoid.MaxHealth == math.huge then
print("Infinity")
end
end
end)