Advanced Flashlight (Horror Game)

FLASHLIGHT MODULE (UPDATED)

I have been seeing many people wondering about how to make a flashlight with a ring and follows the player camera like Apeirophobia, I have created a module that is open source just for that. Mind you this would be ALOT better with ray casting but I didn’t add it. I made it very very easy to use as well. The requirements needed for this is Basics of Module Scripts and Future lighting.

Post Solution: Help

Module: Flashlight Module Source

JUST STATING THAT THIS MODULE IS NOT MEANT FOR THIRD PERSON USES

How to use:

Tutorial: Video

Script:

-- Local Script in startercharacterscripts --

local Character = script.Parent

local Humanoid = Character:WaitForChild("Humanoid")
local HRP = Character:WaitForChild("HumanoidRootPart") -- any object

local FlashlightModule = require("LOCATION OF MODULE") -- People that have no knowledge of module scripts always mess up on this part. This tutorial was made for the people who have knowledge but I'll cover this any ways. If your module is placed in the local script put "require(script:WaitForChild("FlashlightModule"))" and that's it.

local UIS = game:GetService("UserInputService")

local On = false
local db = false

local function Emission()
	if not db then
		db = true
		
		if not On then
			if Humanoid.Health > 0 then
				On = true

				FlashlightModule.CreateFlashlight(HRP)
				game.ContextActionService:SetTitle("Flashlight", "Off")
			end
		else
			if Humanoid.Health > 0 then
				On = false

				FlashlightModule.RemoveFlashlight(HRP)
				game.ContextActionService:SetTitle("Flashlight", "On")
			end
		end
		
		wait(1)
		db = false
	end
end

Humanoid.Died:Connect(function()
	if On then
		FlashlightModule.RemoveFlashlight(HRP)
	end
end)

game.ContextActionService:BindAction("Flashlight", Emission, true, Enum.KeyCode.F or Enum.KeyCode.ButtonB)
game.ContextActionService:SetPosition("Flashlight", UDim2.new(0.2, 105,0.2, 0))
game.ContextActionService:SetTitle("Flashlight", "On")

** Working Flashlight Script **

Video Demonstration:

Test Place: Game
(There are next bots in the game!)

Most of all, please enjoy this module and like it! :wave:

UPDATE: The “jitteriness” is not from the module itself but the game’s lighting. Tweak the shadow properties a bit and It will look better.

105 Likes

where do i put the module?
i never use em

1 Like

Inside the local script, replicated storage maybe? Pretty much anywhere as long as you link a source on where it is in the local script.

I recommend local script.

3 Likes

Is this on client and server side?

1 Like

This flashlight runs completely on CLIENT SIDED* (made a mistake). If it ran server sided everyone would see the players flashlight follow their camera. That’s why it is your decision to add your OWN server sided flashlight coming from the players torso.

4 Likes

Hello!

First of all, I want to say that this is an epic module and thanks for open sourcing it.

Quick question, is there any way to fix the “Buggyness” of it?
In the video, and in my test world, the light is glitchy.

I was thinking about it for a while, how to make a light that does not bug.
What if there was a imageframe (Covering the whole screen), when you have the light off, its a semi-transparent solid image, then when the light is on, there is a little “Cutout” in the middle.

This combined with a light might give a better result. Very unsure though… just wanted to double check I am not missing something before I spend ages trying to get my theory to work.

Thanks,
Lord

2 Likes

I wouldn’t like images. In games like apeirophobia you can see the “jitteriness” of the ring. They cover it up by adding a walk animation to the light.

PS: Also the jitteriness of the looking can be covered up by tween or lerp speed. But yeah, glad most of you are liking this post. Keep liking so more people can come upon this post :smile:

2 Likes

Did the LocalScript in StarterCharacterScripts update? I did everything right but it shows in my Console that ‘Attempted to call require with invalid argument(s).’

EDIT: I forgot i placed FindFirstChild instead of WaitForChild.

2 Likes

This an amazing module btw so thank you for open sourcing it. I am curious how you would make this server sided as I have been experimenting around with this module and the only way I can think of doing it would be to send the players camera CFrame with remote events every .2 seconds or so to update the light part. Is there a better method to replicate this?

3 Likes

you could always just do client-server replication via RemoteEvents

3 Likes

Thank you for clearing this up, haven’t been on lately cause of school and stuff.

1 Like

Instead of loops try using RunService. It is way more optimized and doesn’t hurt performance as much as while loops do. RunService updates with the frames you see so it would be smooth

2 Likes

I haven’t updated this module in a while but I assure you I will add much more in the near future.

2 Likes

I have spawns placed around the map but when i use this flashlight module it makes me go any where else but the spawns

2 Likes

everything works fine! but the problem is that when i turn it on i gotta wait a few seconds for it to be a ring n stuff. how do i fix this???

1 Like

I will try updating the module, thanks for calling this bug out. I have flexible times now

1 Like

Love this module, really helped out with my horror game.

2 Likes

Hey man! Love the module, and thanks for it btw. Is there by any chance I could edit it for mobile players?

2 Likes

The localscript already supports mobile, console, pc, and vr so you don’t need to do anything but if you want you can make it better. I have no issues with that! :grin:

2 Likes

Awesome! Thanks for the module, its amazing.

1 Like