I created a flashlight gear for my game that moves based on where the player’s camera is pointing.
I tested with some friends, and the flashlight beams of other players do not appear.
How can I make the flashlight appear properly on other clients?
local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local Flashlight = script.Parent
local Camera = workspace.Camera
Flashlight.Activated:Connect(function() --Activated
if Flashlight.Handle.Light.SpotLight.Enabled == true then
Flashlight.Handle.Light.SpotLight.Enabled = false
Flashlight.Handle.Sound:Play()
else
Flashlight.Handle.Light.SpotLight.Enabled = true
Flashlight.Handle.Sound:Play()
end
end)
Flashlight.Equipped:Connect(function() --Equipped
for _, Light in pairs(Flashlight.Handle.Light:GetChildren()) do
Light.Enabled = false
end
Flashlight.Handle.equip:Play()
end)
Flashlight.Unequipped:Connect(function() --Unequipped
Flashlight.Handle.equip:Play()
end)
while wait() do --this section of code makes the light point away from the camera
--print("im looping")
if plr.Character:FindFirstChildOfClass("Tool") then
--print("equipped!")
Flashlight.Handle.Light.CFrame = CFrame.new(
Vector3.new(Flashlight.Parent.Head.CFrame.X, Flashlight.Parent.Head.CFrame.Y, Flashlight.Parent.Head.CFrame.Z),
Vector3.new(Camera.CFrame.X, Camera.CFrame.Y, Camera.CFrame.Z)
) * CFrame.Angles(0, math.pi, 0)
end
end
I’ve looked at the code of other flashlight gears in the toolbox, which all replicate properly and have the exact same event connection. I’m stumped why mine isn’t working.
Is it related to my light movement code?