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

Can I get some help with my Flashlight Battery GUI?

My flashlight Battery GUI doesn't work.

player = script.Parent.Parent.Parent
char = player.Character
battery = script.Battery -- Starts at 100.
light = char.Flashlight.Handle.SpotLight

function batteryLife()
	if light.Enabled == true then repeat
		wait(1)
		battery.Value = battery.Value - 1 -- Goes down by 1 every second.
		until battery.Value == 0
	end
	script.Parent["Battery Frame"].%Battery.%Battery.Value = "Battery:".. battery.Value.. "%"
end


char.Flashlight.Activated:connect(batteryLife)

No part of this script works.

EDIT: Still doesn't work. Is there anything else that can be added/fixed?

3 answers

✓ Accepted answer

This also looks broken to me.

repeat until battery.Value == 0

Repeat is supposed to be used in this way:

repeat
--do stuff
until [bool]

2 comments

0

Oh thanks! This is my first time using repeat. Thanks for clearing this up for me.

0

I changed my script but it still doesn't work for some reason. Can you think of anything else?

I think you forgot to call the function

1 comment

0

Ah thanks! I can't believe I forgot that! :P

This should work.

player = script.Parent.Parent.Parent
char = player.Character
battery = script.Battery -- Starts at 100.
light = char.Flashlight.Handle.SpotLight

function batteryLife()
	if light.Enabled == true then
		repeat
			wait(1)
			battery.Value = battery.Value - 1 -- Goes down by 1 every second.
		until battery.Value == 0
	end
	script.Parent["Battery Frame"].Battery.Battery.Value = "Battery:".. battery.Value .. "%" -- This line caused problems, if the name of whatever you access ACTUALLY has % signs in it, you do it for example like game.Workspace["%battery"].lol Use a format like that
end

char.Flashlight.Activated:connect(batteryLife)

2 comments

0

Ah thanks! I actually created a whole different script already but thanks for telling me what was wrong!

0

You're welcome.

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