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.