How to make energy bar that is restored by sleeping?

Hi,

Is it possible to make an energy bar that can be restored when the player sleeps on a bed? Something like in Bloxburg.

How do I begin making this?

1 Like

First you need a variable for insomnia and then you make it decrease all the time. After you have that you make a function for the bed when you lay in it that brings up the bar. The bar I don’t know how to make but you can search that up.

local insomnia = 100

local insomniaDebounce = false
local layingBed = false

while not insomniaDebounce do
	insomnia -= 1
	wait(1)
end

while layingBed do
	insomniaDebounce = true
	insomnia += 1
	wait(1)
end	

workspace.Bed.ClickDetector.MouseClick:Connect(function()
	if not layingBed then
		layingBed = true
	else
		layingBed = false
		insomniaDebounce = false
	end
end)

Note: I have not tested this.

1 Like

It’s not working for me :frowning: Any alternatives for this?

Did you remember to change the bed and clickdetector?