Help trying to see when player is holding and then letting go of key

You can write your topic however you want, but you need to answer these questions:
I want This spotlight to be enabled whenever left control is held down and then be disabled when not held down

I have no clue how to do it as i have tried looking on this forum and there was a few things like i tried UIS.InputEnded and other things but it doesnt seem to work. I even tried just enabling the flashlight with a keybind nothing special and it wouldnt enable from there so i believe that one of the if statements may not be working properly.

--This script is the simple one where the flashlight just doesnt enable.
local UIS = game:GetService("UserInputService")
local toggle = false

UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftControl then
		if script.Parent.AtDoor == true then
			--if workspace.CurrentCamera.CFrame == workspace.House.Mainroom.Doors.Door2FlashLight.CFrame then
				if toggle == false then
				toggle = true
				workspace.House.Mainroom.Doors.Door2FlashLight.SpotLight.Enabled = true
				else
				toggle = false
				workspace.House.Mainroom.Doors.Door2FlashLight.SpotLight.Enabled = false
				end
			end end end)

try printing something in if script.parent.atdoor and tell me if it prints it.

maybe just don’t use toggle variable and do something like this:

workspace.House.Mainroom.Doors.Door2FlashLight.SpotLight.Enabled = workspace.House.Mainroom.Doors.Door2FlashLight.SpotLight.Enabled == false

You can try this:

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.LeftControl then
        if script.Parent.AtDoor == true then
            workspace.House.Mainroom.Doors.Door2FlashLight.SpotLight.Enabled = true
        end
    end
end)

UserInputService.InputEnded:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.LeftControl then
        if script.Parent.AtDoor == true then
            workspace.House.Mainroom.Doors.Door2FlashLight.SpotLight.Enabled = false
        end
    end
end)

how did you made that gray box to put script in? i am new to posting on dev forum and i don’t know how.

you use this three of these"```"

1 Like

Its still not working, thats odd

maybe there is something wrong with script.Parent.atDoor
is it a booleanValue? if yes then you should use script.Parent.atDoor.Value

I put a print statement and it didnt print so one of the if statements are not working properly

I think that might be the issue let me try

Try what Bubas said, add .Value after AtDoor

Yes that was the issue thank you guys

1 Like