Exists on the client but not on the server

I’m using a remote event to communicate with the client and server for a raycast.
The results of the raycast made on the client come back nil in the server
Please help

Server script:

CMF.OnServerEvent:Connect(function(player, result)
	print(result)
end)

Local Script:

CMF.OnClientEvent:Connect(function(clone, raycastRadius, direction)
	local raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.Exclude
	raycastParams.FilterDescendantsInstances = {clone, folderstoignore, game.Workspace.Bullets.TurretBulletProp}
	result = workspace:Spherecast(clone.Position, raycastRadius, direction, raycastParams)
	if result ~= nil then
		print(result)
		CMF:FireServer(result)
	end
end)

Output:

1 Like

I don’ t get why you would do the Raycast on client though. Not only it’ s vulnerable it’ s inefficient too, have you tried doing the raycast on server?
If you did it on client with clientsided instances then obviously it will act like that as it doesn’ t exist on server.

1 Like

Raycasts return an instance, not the actual data. So, the issue you are encountering is the server attempting to access an instance that only exists on the client. If you absolutely have to do it on the client, you can just pass a table with all the properties needed to the server.

Try adding a task.wait() before CMF:FireServer. This could help you out. If it doesn’t let me know and Ill do some deeper digging.

what fires the client to the server? The reason i ask is because until the server sends a remote to client the client wont send a remote to server.

It’s not the server script so I’m confused.

The issue is an argument returning nil, not the remote event failing to fire. This is just simply because he did a client-sided sphere cast instead of doing It server-sided. So it’s a relatively simple fix.

OH, I goofed and read your comment wrong. I thought you had it flipped. I see what you’re saying now. I am incorrect of my method.

The verbage I flipped was instance v. data.

1 Like

I know this is a month later, but thought I give my input for future readers. It seems that you can not send result to the server from the client from my experience. To avoid latency, you need to do the raycast on the client. You would need to send the origin and direction to the server and I guess use that data from the client to do the raycast on the servers end. When I say do not do raycast on the server, I am talking about taking the origin and direction from the server as their is latency.