I have a flashlight script that lets you see the light on both client and server
The issue is that the serverside light appears on the client and I dont want it to.
I want the client to only be able to see the smooth clientside light (smooth as in not stuttery)
and I want to see other peoples flashlights (the stuttery serverside ones)
The clientside script:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local head = character:WaitForChild(“Head”)
local remoteEvent = game.ReplicatedStorage:WaitForChild(“LightPositionEvent”)
local part = nil
local function updateLightPosition()
local camera = workspace.CurrentCamera
if camera and part then
local cameraLook = camera.CFrame.LookVector
part.CFrame = CFrame.new(head.Position, head.Position + cameraLook)
remoteEvent:FireServer(part.CFrame) – Send the light’s CFrame to the server
end
end
game:GetService(“RunService”).RenderStepped:Connect(updateLightPosition)
– Create the light part when this LocalScript loads
part = Instance.new(“Part”)
part.Size = Vector3.new(0.2, 0.2, 0.2)
part.Anchored = true
part.CanCollide = false
part.BrickColor = BrickColor.new(“Bright red”)
part.Parent = game.Workspace
local spotlight = Instance.new(“SpotLight”)
spotlight.Range = 25
spotlight.Brightness = 5
spotlight.Angle = 45
spotlight.Parent = part
The serverside script:
local remoteEvent = game.ReplicatedStorage:WaitForChild(“LightPositionEvent”)
local spotlightCFrame = CFrame.new(Vector3.new(0, 0, 0)) – Initial CFrame
remoteEvent.OnServerEvent:Connect(function(player, cframe)
spotlightCFrame = cframe – Receive the light’s CFrame from the client
end)
– Function to replicate the light’s position to all clients
local function replicateLightPosition()
local part = game.Workspace:FindFirstChild(“ReplicatedLight”)
if part then
part.CFrame = spotlightCFrame
end
end
game:GetService(“RunService”).Heartbeat:Connect(replicateLightPosition)
– Create the light part on the server
local part = Instance.new(“Part”)
part.Size = Vector3.new(0.2, 0.2, 0.2)
part.Anchored = true
part.CanCollide = false
part.BrickColor = BrickColor.new(“Bright red”)
part.Name = “ReplicatedLight”
part.Parent = game.Workspace
local spotlight = Instance.new(“SpotLight”)
spotlight.Range = 25
spotlight.Brightness = 5
spotlight.Angle = 45
spotlight.Parent = part
There is a remoteevent in replicatedstorage called LightPositionEvent