Flashlight script not working?

Hello! So I am making a localscript for a flashlight and I want a limit on it. I scripted it but none of the values are working and all it does it just turn on but doesnt do anything with the vaubles?


local player = game.Players.LocalPlayer
local character = player.Character
local FlashlightBattery = script:WaitForChild("FlashlightBattery")
local FlashlightOn = script:WaitForChild("FlashlightOn")
local Flashlight = script.Parent

local UserinputService = game:GetService("UserInputService")

	if input.KeyCode == Enum.KeyCode.F then
		if FlashlightBattery.Value < 10 then
			while FlashlightOn.Value == "Off" do
					FlashlightBattery.Value = FlashlightBattery.Value - 1
					FlashlightOn.Value = "On"
					Flashlight.Front.SurfaceLight.Enabled = true
					Flashlight.Light.Light.Enabled = true
					Flashlight.Light.Shadow.Enabled = true
					if FlashlightBattery.Value == 0 then
						FlashlightOn.Value = "Off"
					while FlashlightOn.Value == "On" do
						FlashlightBattery.Value = 	FlashlightBattery.Value + 1
						FlashlightOn.Value = "Off"
						Flashlight.Front.SurfaceLight.Enabled = false
						Flashlight.Light.Light.Enabled = false
				Flashlight.Light.Shadow.Enabled = false

Which variables don’t work, and what do they need to achieve/do?

I have a 2 values called Flashlight battery and flashlight on whitch checks if flashlight is on and off

You dont need to do that:
For Example:

Light.Enabled = not Light.Enabled

Do you know what state those values are in when they stop working, like what values?

Also do you have an IF statement that when the f key is pressed the flashlight turns off?


Maybe try these suggestions?

The “If” would be better off as a while.

The “while” would be better off as an if.

And what do you mean it doesn’t do anything with the values?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.