Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make a flashlight like this?

What I want to replicate: https://youtu.be/bWK0T6Femug

I know basic scripting, and this looks as if it's just a gui and a pointlight. I can do the scripting for something like this probably, but I just want a confirmation that my guess is correct.

7 comments

0

This is a Pointlight, though not a GUI. The Pointlight is actually positioned relative to the CurrentCamera for this effect.

0

@Feahren Do you have any idea on how I could do this?

0

I’d assume using RenderService’s RenderStepped Signal to tie a Listener refreshing the PointLight to face the direction of the CurrentCamera’s CoordinateFrame.

0

It would be best to use a Part to replicate the CoordinateFrame and attach the PointLight to it instead.

0

I suggest looking both of CameraManipulation and RenderService get a better understanding

0

Somewhat like the Script I posted below

0

If the Script does work, accept it:) Help me Help you!

1 answer

✓ Accepted answer

From the observation I gave with the provided Video, I will assure you it’s not a GUI, though to me it seems like the PointLight is being projected relatively to the CurrentCamera of the LocalPlayer.

The best way I’d assume this was achieved was having a Part imitate the current CoordinateFrame of the Camera, and having a PointLight attached to the Part.

To get the smoothest function to refresh the Part’s CoordinateFrame relative to the Camera’s, I’d use RenderService’s RenderStepped Signal, as it fires every Rendered Frame.

local Player = game:GetService("Players").LocalPlayer
local Camera = workspace.CurrentCamera
local Part = workspace.Part --// Preferably CanCollide is off and the Transparency is 0.

Part.Parent = Camera

local RenderService= game:GetService("RenderService")
local Stepped = RenderService.RenderStepped:Connect(function()
   if not (Part) then Stepped:Disconnect() --// If for some reason the Part becomes nil, it’s best to not leave a pointless function running every frame.
   Part.CFrame = Camera.CFrame
end)

1 comment

0

This is the closest I can get you, I can do some more experimenting though, and maybe repost. If this does work, don’t forget to accept this answer!

This discussion is preserved as it was. New answers, comments, and votes are closed.