I’m working on a gun system that requires sending rayParams thorugh a remoteEvent to make sure the bullets travel correctly, but when I try to get the rayParams in the client/server from the remoteEvent the rayParams are nil.
RemoteEvents/RemoteFunctions are restricted in the types of values they can transmit across the client-server boundary, you’ll need to serialize the RaycastParam object first into primitive values and then deserialize those values back into a RaycastParam object on the other side, i.e;
--CLIENT
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local replicated = game:GetService("ReplicatedStorage")
local remote = replicated:WaitForChild("RemoteEvent")
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.IgnoreWater = true
local raycastParamsData = {}
raycastParamsData["FilterDescendantsInstances"] = raycastParams.FilterDescendantsInstances
raycastParamsData["FilterType"] = Enum.RaycastFilterType.Blacklist
raycastParamsData["IgnoreWater"] = true
remote:FireServer(raycastParamsData)
--SERVER
local replicated = game:GetService("ReplicatedStorage")
local remote = replicated.RemoteEvent
remote.OnServerEvent:Connect(function(player, raycastParamsData)
local raycastParams = RaycastParams.new()
for raycastParamsProperty, raycastParamsValue in pairs(raycastParamsData) do
raycastParams[raycastParamsProperty] = raycastParamsValue
end
print(raycastParams.FilterDescendantsInstances) --table
print(raycastParams.FilterType) --Enum.RaycastFilterType.Blacklist
print(raycastParams.IgnoreWater) --true
end)