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
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)
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.
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.
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.
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.