Here is my script. As the client trying to cast the ray you can see it, but other clients cannot see the ray.
local function fire()
-- Checks
if canShoot:InvokeServer() then
--Initialize
if recoilTrack then
recoilTrack:Play()
end
flashGui.Enabled = true
-- Cast Ray
local ray = Ray.new(hole.CFrame.p, (mouse.hit.p - hole.CFrame.p).unit * range.Value)
local touch, position = workspace:FindPartOnRay(ray, player.Character, false, true)
-- Hit Detection
if touch then
hitRemote:FireServer(touch)
end
shootRemote:FireServer()
-- Trace
if allowTracing.Value then
-- Create
local trace = Instance.new("Part")
trace.Anchored = trace
trace.CanCollide = false
trace.Transparency = 0.5
trace.BrickColor = BrickColor.new("White")
trace.Material = Enum.Material.SmoothPlastic
-- Calculate
local distance = (hole.CFrame.p - position).magnitude
trace.Size = Vector3.new(0, 0, distance)
trace.CFrame = CFrame.new(hole.CFrame.p, position) *CFrame.new (0, 0, -distance/2)
trace.Parent = workspace
-- Clean-up
game:GetService("Debris"):AddItem(trace, 0.1)
wait(0.1)
flashGui.Enabled = false
end
end
end
