Flashlight script not working

I have an flashlight script, but it’s just only working for one of people in server. For other players, it’s not working. I have an remote system that enables or disables the script. I’ll put the scripts here:

--Flashlight script on StarterCharacterScripts.FirstPerson
local flashlightModule = require(game.ReplicatedStorage.Modules:WaitForChild("Flashlight"))
local uis = game:GetService("UserInputService")
local toggled = false

uis.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.F then
		if toggled == false then
			toggled = true
			flashlightModule.toggleFlashlight(game.Players.LocalPlayer.Name, true)
		elseif toggled == true then
			toggled = false
			flashlightModule.toggleFlashlight(game.Players.LocalPlayer.Name, false)
		end
	end
end)
--Flashlight ModuleScript on ReplicatedStorage.Modules

local flashlight = {}

function createlight(plrName)
	local char = workspace:FindFirstChild(plrName)
	if not char then
		return
	end

	local head = char:WaitForChild("Head")
	local light = head:FindFirstChild("headlight")
	if light then
		light:Destroy()
	end

	local makelight = Instance.new('SpotLight', head)
	makelight.Name = "headlight"
	makelight.Angle = 100
	makelight.Range = 33
	makelight.Shadows = true
	makelight.Brightness = 1.7
end

function flashlight.toggleFlashlight(plrName, status)
	if status == false then
		local headlight = workspace:FindFirstChild(plrName):WaitForChild("Head"):FindFirstChild("headlight")
		if headlight then
			headlight:Destroy()
			script.off:Play()
		end
	elseif status == true then
		createlight(plrName)
		script:FindFirstChild('on'):Play()
	end
end

return flashlight
--This is how the script is controlled from client round script on StarterCharacter

script.Parent:WaitForChild("FirstPerson"):WaitForChild("Flashlight").Enabled = true

script.Parent:WaitForChild("FirstPerson"):WaitForChild("Flashlight").Enabled = false

Basically, I’m enabling or disabling to control it. I don’t know why it’s happening.

It’s possible that the light isn’t being replicated to the server (and therefore other players). Try making a remote event that fires the server, which then creates the light in the player character.

Hi there, I’d like to let you know that your code is currently client-only. You will need to use a RemoteEvent to replicate the light to the server. Your code however, needs to be secured for this as currently an exploiter would be able to just spam lights to any child in the workspace. The fix for this is to check if game.Players:FindFirstChild(plrName) ~= nil

Also you should remove the script.Parent:WaitForChild(“FirstPerson”):WaitForChild(“Flashlight”).Enabled = false
line from your code as it is disabling whatever is named “Flashlight”

Please let me know if any more errors occur/you need more help.