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

Power Drainage?

Asked by 9 years ago

I want to make it so when you hold down the Button for a Flashlight, the Power percentage drops from 100, but the Script breaks when I try this in the main function:

mouse.KeyDown:connect(function(key)
    if string.byte(key) == 50 then
        L.Enabled = true
while wait(3) do
    game.Lighting.PValue.Value = game.Lighting.PValue.Value - 1
end
    end
end)

The script inside the GUI:

while true do
    script.Parent.Text = game.Lighting.PValue.Value
end

1 answer

Log in to vote
2
Answered by 9 years ago
mouse.KeyDown:connect(function(key)
    if string.byte(key) == 50 then
        L.Enabled = true
while wait(3) do
    game.Lighting.PValue.Value = game.Lighting.PValue.Value - 1
end
    end
end)

This is the script with the main error, a while loop needs a wait(), therefore I have changed true to wait().

while wait() do
    script.Parent.Text = game.Lighting.PValue.Value
end
Ad

Answer this question