Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can I get some help with my Flashlight Battery GUI?

Asked by
Nifer2 174
10 years ago

My flashlight Battery GUI doesn't work.

01player = script.Parent.Parent.Parent
02char = player.Character
03battery = script.Battery -- Starts at 100.
04light = char.Flashlight.Handle.SpotLight
05 
06function 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.. "%"
13end
14 
15 
16char.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

Log in to vote
2
Answered by
3rdblox 30
10 years ago

This also looks broken to me.

1repeat until battery.Value == 0

Repeat is supposed to be used in this way:

1repeat
2--do stuff
3until [bool]
0
Oh thanks! This is my first time using repeat. Thanks for clearing this up for me. Nifer2 174 — 10y
0
I changed my script but it still doesn't work for some reason. Can you think of anything else? Nifer2 174 — 10y
Ad
Log in to vote
2
Answered by 10 years ago

I think you forgot to call the function

0
Ah thanks! I can't believe I forgot that! :P Nifer2 174 — 10y
Log in to vote
1
Answered by
iaz3 190
10 years ago

This should work.

01player = script.Parent.Parent.Parent
02char = player.Character
03battery = script.Battery -- Starts at 100.
04light = char.Flashlight.Handle.SpotLight
05 
06function 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
14end
15 
16char.Flashlight.Activated:connect(batteryLife)
0
Ah thanks! I actually created a whole different script already but thanks for telling me what was wrong! Nifer2 174 — 10y
0
You're welcome. iaz3 190 — 10y

Answer this question