So, my flashlight won’t turn on/off here’s some informations:
What do I want to achieve?
-Basically when I press F the flashlight turns on/off.
What is the issue?
-When I press F it just keeps printing “turning on” but doesn’t do anything.
More Information
-My flashlight is a script inside of StarterCharacterScripts.
-The flashlight isn’t a GUI.
Here’s the script:
local UIS = game:GetService("UserInputService")
local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local LightOn = false
game.StarterPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
UIS.InputBegan:Connect(function(input,chatting)
if LightOn == false and input.KeyCode == Enum.KeyCode.F and chatting == false then
player.Character.Flashlight.Disabled = false
print("turning on")
elseif LightOn == true and input.KeyCode == Enum.KeyCode.F and chatting == false then
player.Character.Flashlight.Disabled = true
print("turning off")
end
end)
As @kaizenmarcell said, Disabled isn’t a thing.
Also why are you adding a conditional statement to elseif?
if LightOn == false and input.KeyCode == Enum.KeyCode.F and chatting == false then
player.Character.Flashlight.Disabled = false
print("turning on")
elseif LightOn == true and input.KeyCode == Enum.KeyCode.F and chatting == false then
player.Character.Flashlight.Disabled = true
print("turning off")
end
Make it more simple by doing this:
if input.KeyCode == Enum.KeyCode.F and chatting == false then
if player.Character.Flashlight.Enabled == false then
player.Character.Flashlight.Enabled = true
print("turning on")
else
player.Character.Flashlight.Enabled = false
print("turning off")
end
end
I recommend just doing this to simplify it, it’s a lot more efficient than what you’re doing by the way and should also fix the issue!
UIS.InputBegan:Connect(function(input,chatting)
local flashlight = player.Character.Flashlight
if input.KeyCode == Enum.KeyCode.F and not chatting then
flashlight.Disabled = not flashlight.Disabled
print("switching")
end
end)