local plr = game.Players.LocalPlayer function onKeyDown(key, mouse) if key:lower() == "e" and ((game.Players.Player1.Character.Torso.Position - game.Workspace.Interactables.Switches.AA.Position).magnitude) < 100 then local lightName = "AA" for i, aa in pairs(game.Workspace.Interactables.Lights:FindFirstChild(lightName):GetChildren()) do if aa:FindFirstChild("Light").Brightness == 1000 then aa:FindFirstChild("Light").Brightness = 0 else aa:FindFirstChild("Light").Brightness = 1000 end end end end mouse.KeyDown:connect(function(key) onKeyDown(key, mouse) end)
Trying to get this to work when you push E and you are close enough to the button it'll turn off the lights. No output and doesn't even print 1. Its in a localscript in starterpack
Edited!
Try this:
function onKeyDown(key, mouse) if key:lower() == "e" and ((game.Players.Player1.Character.Torso.Position - game.Workspace.Interactables.Switches.AA.Position).magnitude) < 100 then -- Add rest of your stuff here mouse.KeyDown:connect(function(key) onKeyDown(key, mouse) end)
Fixed :) If anyones wondering how its this script.
function keydown(k) if k:lower() == "e" and ((game.Players.Player1.Character.Torso.Position - game.Workspace.Interactables.Switches.AA.Position).magnitude) < 100 then for a, aa in pairs(game.Workspace.Interactables.Lights.AA:GetChildren()) do aa.Light.Brightness = 0 end end end m = script.Parent.Parent:GetMouse(); m.KeyDown:connect(keydown)