Flashlight system not working

Hi everyone,

I’m attempting to create a script where all players can see a light moving when the player moves their mouse. I started with a great script from this video:

However, I noticed that it was on a LocalScript, meaning no one else could see the light moving. Thus, I used a pair of Remote Events to try and connect the original modified script and a normal Script.

Edit: There are no errors in Output. When I equip the light, it doesn’t move.

Here’s the model if you want to see what’s wrong:
Flashlight.rbxm (30.9 KB)
Make sure to put it in StarterPack.

Layout:

image

Local Script

local cam = workspace.CurrentCamera
local RS = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Clone = script.Parent:WaitForChild("LightPart")
local light = script.Parent:WaitForChild("Light")
local move = script.Parent:WaitForChild("Move")

local Brightness = 10

local Keybind = Enum.KeyCode.F

local UIS = game:GetService("UserInputService")

local Toggle = false

local Mouse = game.Players.LocalPlayer:GetMouse()

UIS.InputBegan:Connect(function(Input, p)
	if script.Parent.Equipped then
		if p then return end
		if Input.KeyCode == Keybind then
			light:FireServer(Toggle)
			Toggle = not Toggle
		end
	else
		return
	end
end)

script.Parent.Unequipped:Connect(function()
	Toggle = false
end)

RunService.RenderStepped:Connect(function()
	if Clone then
		if not Toggle then
			Clone.Position = cam.CFrame.Position
			move:FireServer(Mouse.Hit.Position)
		end
	end
end)

Server Script

local light = script.Parent:WaitForChild("Light")
local move = script.Parent:WaitForChild("Move")

local Clone = script.Parent:WaitForChild("LightPart")

local TS = game:GetService("TweenService")
local TI = TweenInfo.new(.1, Enum.EasingStyle.Sine)

local Brightness = 10

move.OnServerEvent:Connect(function(p, pos)
	TS:Create(Clone, TI, {CFrame = CFrame.lookAt(Clone.Position, pos)}):Play()
	print(pos)
end)

light.OnServerEvent:Connect(function(p, bool)
	if bool then
		TS:Create(Clone.SpotLight, TI, {Brightness = Brightness}):Play()

	else
		TS:Create(Clone.SpotLight, TI, {Brightness = 0}):Play()
	end
end)

Can anyone help? Anything is appreciated.

Thank you!

1 Like

I will start with that I am not familiar with the script that you are trying to use, so I will just try to guide you to fixing the main issue.
The main problem is that you are trying to fire a remote event to a server script that is not running on the server. The script that you are trying to connect to is a local script and will only run locally. The [LocalScript] tag at the top of the script is an indicator that this is a local script. You will need to make a new server script and put the code from the local script that you are trying to connect to. You also need to make sure that the server script is in server storage.
I would also suggest putting the code that is in the server script into a function that can be called by the remote event. That way it is easier to manage and you don’t need to make separate events for turning the light on and off.