Hello! I have created a simple but effective first-person flashlight script. Now, this is mainly for horror games, but can be used in any way. I have made this for a beginner scripter and / or someone who doesn’t know how to script. Also, make sure that this is in a Local script or else, it wont work.
The script:
-- Variables
local player = game:GetService("Players").LocalPlayer
local char = player.Character
local hum = char:WaitForChild("Humanoid")
local UpperTorso = char:WaitForChild("UpperTorso")
local UIS = game:GetService("UserInputService")
-- Making the flashlight and parenting it to the UpperTorso
local flashlight = Instance.new("PointLight")
flashlight.Brightness = 1
flashlight.Shadows = true
flashlight.Enabled = false
flashlight.Range = 32
flashlight.Parent = UpperTorso
-- on and off
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftControl then -- Change LeftControl to the key you want that will turn on the flashlight
flashlight.Enabled = true
end
end)
UIS.InputEnded:Connect(function(input)
flashlight.Enabled = false
end)
Feel free to show easier ways to make this script, I just chose what worked best for me.
Happy developing, and happy Halloween!