#why wont my flashlight script work?

1 messages · Page 1 of 1 (latest)

whole flame
#

I have a flashlight script in StarterPlayerScripts as a Local Script

-- Flashlight Script

-- SERVICES
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer
local camera = workspace.CurrentCamera

-- SETTINGS
local TOGGLE_KEY = Enum.KeyCode.F
local BRIGHTNESS = 3
local RANGE = 60
local ANGLE = 55
local COLOR = Color3.fromRGB(255, 245, 220)

-- STATE
local flashlightOn = false

-- CREATE SPOTLIGHT
local flashlight = Instance.new("SpotLight")
flashlight.Name = "Flashlight"
flashlight.Enabled = false
flashlight.Brightness = BRIGHTNESS
flashlight.Range = RANGE
flashlight.Angle = ANGLE
flashlight.Color = COLOR
flashlight.Shadows = true
flashlight.Parent = camera

-- OPTIONAL CLICK SOUND
local click = Instance.new("Sound")
click.SoundId = "rbxassetid://9070807695"
click.Volume = 0.5
click.Parent = camera

-- INPUT
UserInputService.InputBegan:Connect(function(input, gp)
    if gp then return end

    if input.KeyCode == TOGGLE_KEY then
        flashlightOn = not flashlightOn
        flashlight.Enabled = flashlightOn
        click:Play()
    end
end)

-- FOLLOW CAMERA
RunService.RenderStepped:Connect(function()
    if flashlight.Enabled then
        flashlight.CFrame = camera.CFrame
    end
end)
warm shoal
#

bingo

#

u dont see the error?

whole flame
#

.

leaden oasisBOT
#

studio** You are now Level 1! **studio

warm shoal
#

comment out this

#

-- FOLLOW CAMERA
RunService.RenderStepped:Connect(function()
if flashlight.Enabled then
flashlight.CFrame = camera.CFrame
end
end)

#

and see what happens

whole flame
#

I might've missed a key piece of information

warm shoal
#

which is

#

?

#

@whole flame

whole flame
#

the error

#

also what does "commenting out" mean

#

oh wait

#

nevermind did it

#

but now the issue is that how is the flash light supposed to follow the player?

#

@warm shoal

warm shoal
whole flame
#

its not though, its im assuming at 0,0,0

warm shoal
#

hmmm

#

make a part in ur head when ur join called "FlashlightPart"

#

and

#

parent it to that

#

instead

whole flame
#

ok, and is that with all the same previous code?

warm shoal
#

no like

whole flame
# warm shoal wym

do i use the same code except the light itself is parented in a part thats in your head?

warm shoal
#

yes

#

try that

#

if not

whole flame
#

ok

warm shoal
#

rotate the part 90 degrees

whole flame
#

@warm shoal thanks it worked!

warm shoal
#

ur welcome!

#

dont forget to put the "Solved" tag

#

@whole flame