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.

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

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

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]
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.

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)
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