Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why isn't my ray casting for other players?

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

2 answers

With FilteringEnabled, objects created on the client do not automatically replicate to the server, as to mitigate exploits.

You can still do the raycasting on the client, however for the part to be visible to everyone you must create it on the server.

I recommend firing a RemoteEvent to the Server containing all information needed to construct the part that is determined from the Ray. For example, start position, end position, and length.

I would recommend learning how to script instead of copy and pasting code, because that doesn't get you anywhere. Try going to wiki.roblox.com

This discussion is preserved as it was. New answers, comments, and votes are closed.