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

Power Drainage?

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

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

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