RaycastResult can't be sent from Client -> Server?

Local script:

wait(1)

local raycastresult = workspace:Raycast(Vector3.new(0,0,0), Vector3.new(0, -50, 0), RaycastParams.new())
print(raycastresult) --> prints raycast result info
workspace.RemoteEvent:FireServer(raycastresult)

Server script:

game.Workspace.RemoteEvent.OnServerEvent:Connect(function(a,b)
	print(a) --> BullfrogBait (player argument)
	print(b) --> nil
end)

I swear I’ve sent RaycastResults from Client → Server before but I guess I’m remembering it wrong? Is there a problem with my script? The print in the local script confirms it isn’t nil however the server script only prints the player parameter.

You can send the origin, direction and params of the raycast to the server instead of the results so that the server handles the raycast instead:

workspace.RemoteEvent:FireServer(Vector3.new(0, 0, 0), Vector3.new(0, -50, 0), Raycastparams.new())
workspace.RemoteEvent.OnServerEvent:Connect(function(player, origin, direction, params)
    local raycastResult = workspace:Raycast(origin, direction, params)
end)
2 Likes

That’s what I was planning to do, haha. Unfortunate that I can’t send it over in one piece. :confused:

Thanks though.

1 Like

I think that’s due in part to the limitations on what data can be exchanged between the server and the client via a RemoteEvent/RemoteFunction.

Can’t you store them to a table and send it to the server? I did this when making client projectiles, it works perfectly

1 Like

Maybe this will work?

task.wait(1)

local raycastresult = workspace:Raycast(Vector3.new(0,0,0), Vector3.new(0, -50, 0), RaycastParams.new())
if raycastresult then 
	print(raycastresult) --> prints raycast result info
   workspace.RemoteEvent:FireServer({raycastresult})
end
1 Like

I’ll test this out right now, hoping it works. :slight_smile:

Unfortunately doesn’t work, it just returns {}, an empty table.