Need help making a flash light script (kind of)

I need help making a way when a player is in a dark area they can press F and it lightens up an area and it turns off when they press F. Pls help.

1 Like

Well just user input user service

local uip = game:GetService("UserInputService")

uip.InputBegan:Connect(function(input)
 if input.KeyCode == Enum.Keycode.F then
 -- Code here
end)
2 Likes

That code will work I just don’t have a code that will light up a players area do you have one???

Please don’t ask others for code. We can give you pointers (such as using a light in a player’s HumanoidRootPart) but try to write your own before you ask others for their code.

2 Likes
local Character = script.Parent
local Light = Instance.new("PointLight", Character:WaitForChild("HumanoidRootPart"))
Light.Enabled = false
Light.Color = Color3.fromRGB(255, 255, 255)
Light.Brightness = 8
Light.Range = 10
Light.Shadows = true
local UserInputService = game:GetService("UserInputService")
local function onInputBegan(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.F then
			Light.Enabled = not Light.Enabled
		end
	end
end
UserInputService.InputBegan:Connect(onInputBegan)
5 Likes

Ik I was struggling with the light turning on and off so I asked for help.

I wouldn’t recommend a point light for flashlights. Its terrible to get in the habit of doing and when working with lighting you want to try to get it realistic. Even if the game is cartoony. A pointlight flashlight just makes no sense at all.

I’d suggest using either spot lights or surface lights. Preferably spot lights for a flashlight.
But never a pointlight for a flashlight.

2 Likes