Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Best way to make this script hunger instead of healing?

So I have a consume system that heals the player when they click on a text-button. The player is healed the amount of health in a value called 'consume'. I am trying to make it hunger instead of healing meaning I am trying to make it so when the player clicks consume the player's hunger value goes up instead of their health value. ps: sorry if my English isn't so good (both hunger and consume are intvalues)

--(healing script) --Main script (server script) I am trying to swap

elseif Type == "Consume" then
                    table.remove(Player_Data, Index)

                    local Character = Player.Character

                    local Humanoid = Character:WaitForChild("Humanoid")

                    if Humanoid.Health < Humanoid.MaxHealth then
                        Humanoid.Health = Humanoid.Health + Data.Options.Consume
                    end
                end

                break
            end
        end


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------


--(hunger script local script)
local Plr = game.Players.LocalPlayer
local HungerVal = Plr:WaitForChild("HungerVal")


  HungerVal.Value = HungerVal.Value + 70
  if HungerVal.Value >100 then
   HungerVal.Value = 100
  end

1 answer

For lines 10-11, you would want to add a variable inside of your ModuleScript for hunger. So, it would look something like this.

Lines 10-11

if Humanoid.Health < Humanoid.MaxHealth then
	Humanoid.Health = Humanoid.Health - Data.Options.Hunger
end

Or you can use the same variable, and just subtract it. Depends on how you want to do it!

Hope this helped!

If this worked, don't forget to select this as the answer so other people know this question has been solved!

~killerbrenden

3 comments

0

I was wondering how I change health to hunger so instead of humanoid.health it would be something like hunger.value and thank you for the reply you always help me out.

0

You can't really re-name Humanoid properties. You can have a IntValue inside of the player and set that value to their health and name that has Hunger and use that as your Health/Hunger variable.

0

that's a good idea but i wouldn't know how to execute it

This discussion is preserved as it was. New answers, comments, and votes are closed.