How to make a health detection system

so right now im kinda stuck trying to figure out how to make a heath dectection system

my main goal is this

local healthIncrement = 500

local function adjustMaxHealth(originalValue)
	if value.Value % 100 == 0 then
		if value.Value > 5 then
			if value.Value > originalValue then
				model.Humanoid.MaxHealth = model.Humanoid.MaxHealth + 100 * value.Value
			elseif value.Value < originalValue then
				model.Humanoid.MaxHealth = model.Humanoid.MaxHealth - 100 * value.Value
			end
		end
	end
end

i want it so that the function checks if the value is greater then 5 and is not higher then 100, then it checks if the value is either a 1 digit or a double digit then i want it so that the fuction checks if the last digit of the value like (18) is either 5 or 0, and if it is then i want it so that it multiplys by 5 and captures the values value, and if the value changes and its lesser then the value that was caputered i want it to check if the value is either lesser then 5 or like lesser but is the sane as the 5 times table

1 Like
local function adjustMaxHealth(originalValue)
	local orginalvalue = originalValue
	if value.Value % 100 == 0 then
		if value.Value > 5 then
			if value.Value > originalValue then
				model.Humanoid.MaxHealth = model.Humanoid.MaxHealth + 100 * value.Value
			elseif value.Value < originalValue then
				model.Humanoid.MaxHealth = model.Humanoid.MaxHealth - 100 * value.Value
			end
		end
	end
end
local healthIncrement = 500
local originalValue = 10 -- Starting value (you can change this if you want to)
local capturedValue = nil
local model = workspace.Model -- Replace with your model's path considering I don't know it

-- Function to adjust MaxHealth based on specific rules
local function adjustMaxHealth(value)
    local lastDigit = value.Value % 10

    -- Check if the value is between 5 and 100
    if value.Value > 5 and value.Value <= 100 then
        -- This makes sure it's either a single-digit or two-digit number
        if value.Value < 10 or value.Value < 100 then
            -- If the last digit is 5 or 0, multiply the value by 5 and save it
            if lastDigit == 5 or lastDigit == 0 then
                capturedValue = value.Value * 5
                model.Humanoid.MaxHealth = capturedValue + healthIncrement -- Update MaxHealth
            end
        end
    end

    if capturedValue and value.Value < capturedValue then
        -- Check if it's less than 5 or fits the 5-times table
        if value.Value < 5 or value.Value % 5 == 0 then
            model.Humanoid.MaxHealth = model.Humanoid.MaxHealth - healthIncrement
        end
    end
end

local value = workspace.Value -- Change this with your NumberValue because once again, I don't know the name of your NumberValue
value.Changed:Connect(function()
    adjustMaxHealth(value)
end)

I would’ve explained it but scripting it seemed easier so I just decided to do that.

uh what i mean by is that for every 5 in the value, the healthincrement would times by +1 so if the value was 10 then the healthincremented would be 1000 and so on

sorry if i wasted your time

local healthIncrement = 500
local originalValue = 10
local capturedValue = nil
local model = workspace.Model

local function adjustMaxHealth(value)
    local lastDigit = value.Value % 10
    local multiplier = math.floor(value.Value / 5)

    if value.Value > 5 and value.Value <= 100 then
        if lastDigit == 0 then
            capturedValue = value.Value * 100
            model.Humanoid.MaxHealth = capturedValue + healthIncrement * multiplier
        end
    end
    
    if capturedValue and value.Value < capturedValue then
        if value.Value < 5 or value.Value % 5 == 0 then
            model.Humanoid.MaxHealth = model.Humanoid.MaxHealth - healthIncrement * multiplier
        end
    end
end

local value = workspace.Value
value.Changed:Connect(function()
    adjustMaxHealth(value)
end)

No worries its a pretty simple fix

1 Like