My flashlight Battery GUI doesn't work.
01 | player = script.Parent.Parent.Parent |
02 | char = player.Character |
03 | battery = script.Battery -- Starts at 100. |
04 | light = char.Flashlight.Handle.SpotLight |
05 |
06 | function batteryLife() |
07 | if light.Enabled = = true then repeat |
08 | wait( 1 ) |
09 | battery.Value = battery.Value - 1 -- Goes down by 1 every second. |
10 | until battery.Value = = 0 |
11 | end |
12 | script.Parent [ "Battery Frame" ] .%Battery.%Battery.Value = "Battery:" .. battery.Value.. "%" |
13 | end |
14 |
15 |
16 | 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?
This also looks broken to me.
1 | repeat until battery.Value = = 0 |
Repeat is supposed to be used in this way:
1 | repeat |
2 | --do stuff |
3 | until [ bool ] |
I think you forgot to call the function
This should work.
01 | player = script.Parent.Parent.Parent |
02 | char = player.Character |
03 | battery = script.Battery -- Starts at 100. |
04 | light = char.Flashlight.Handle.SpotLight |
05 |
06 | function batteryLife() |
07 | if light.Enabled = = true then |
08 | repeat |
09 | wait( 1 ) |
10 | battery.Value = battery.Value - 1 -- Goes down by 1 every second. |
11 | until battery.Value = = 0 |
12 | end |
13 | 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 |
14 | end |
15 |
16 | char.Flashlight.Activated:connect(batteryLife) |