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

Hunger Bar (How to make the hunger bar decrease?)

Hello, I have been trying to make a hunger bar. My only problem is that the hunger bar isin't moving. Please help.

Here is my current code:

--{0, 294},{0, 33} to {0, 0},{0, 33}
val = Instance.new('IntValue')
val.Parent =game.Players.LocalPlayer
val.Value = 100
val.Name ="val"
val1 = Instance.new('IntValue')
val1.Parent =game.Players.LocalPlayer
val1.Value = 294
val1.Name = "val1"
--script.Parent.Parent.Size = UDim2.new(0,294,0,33) << Here is the script i want help whit.
while true do
	wait(1)
	
	script.Parent.Text = val.Value
	val1.Value = val1.Value - 2.94
	val.Value = val.Value - 1
	print("VAL: "..val.Value)
	print("VAL1: "..val1.Value)
	
end

2 answers

✓ Accepted answer

So i'll show you a fix. Follow the following steps: Step Zero (aka description what we need to do 1st): Do step 6. as 1st

  1. Make two frames, first is HungerBar (green color) and second is HungerBacking (red color). Their size is {0,5},{0,100} so it takes some long to get your hunger lower.
  2. Make a local-script called "ClickFunction".
  3. Insert following code there:
local clicker = game.Workspace.mouse.ClickDetector

clicker.MouseClick:connect(function()
	game.Workspace.RemoteEvent:FireServer()
end)
  1. Create a serverscript called "HungerBar". Insert it into the "HungerBar" GUI instance.
  2. Insert the code;
while true do
	script.Parent.HungerBar.Size = UDim2.new(script.Parent.HungerBar.Size.X, script.Parent.HungerBar.Size.Y - 5)
	wait(1)
end
  1. You may get a stable hunger bar but you need to add a folder. Name the folder as "HungerBarr" (don't take care on a misspell), and put the serverscript and frames into the folder.
  2. Now we need to make an thing that increases hunger status to full. We will use a tool. Let's name it "Apple."
  3. Insert a red sphere called "Handle". Make it small.
  4. Paste the provided code here:
local Tool = script.Parent;

enabled = true




function onActivated()
	if not enabled  then
		return
	end

	enabled = false


	local hb = game.Players.LocalPlayer.PlayerGui.ScreenGui.HungerBarr.HungerBar
	Tool.Handle.DrinkSound:Play()

	wait(3)
	
	local h = Tool.Parent:FindFirstChild("Humanoid")
	if (h ~= nil) then
		if (h.MaxHealth > h.Health + 16) then --DO not forget "then"
			hb.Size.Y = hb.Size + 16 -- Do not delete
			h.Health = h.Health + 16
		else	
			h.Health = h.MaxHealth
		end
	end

	Tool.GripForward = Vector3.new(-.976,0,-0.217) --Do not touch any below
	Tool.GripPos = Vector3.new(0.03,0,0)
	Tool.GripRight = Vector3.new(.217,0,-.976)
	Tool.GripUp = Vector3.new(0,1,0) -- Do not touch any above

	enabled = true

end

function onEquipped()
	Tool.Handle.OpenSound:play()
end

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)

Tada! You get a working bar! Have fun :)

1 comment

0

The scripts seem to be trunctated

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