How do I pass in a variable of type RaycastResult as a parameter?

Hey, I am have having a bit of a problem.

To keep things short - I am trying to pass in a variable of type RaycastResult as an argument to a :FireServer() function in a local script. The issue is that when I try to access it’s properties (In a script) it says:
Attempt to index nil with Property Name

He is a screenshot:

Here, I tried to do


in a local script, and then pass in the raycastResult to the server and try to print it out there, as you can see - it… didn’t work… yea

The questioning template is asking me what solutions I’ve tried so far and honestly - I tried googling for a good amount of time - nothing helped me. I assume, that raycastResult is a table with some stuff in it, so I tried googling “Error passing in a table as an argument Lua” and stuff like that, but the only thing that I found is, drum roll, nothing at all!

So my 2 final questions are:
1.) Is this ok, or am I messing something up?
2.) If it is okay - why is it happening, how do I fix it?
3.) If it is not ok, I can send a full script, it’s not that long, I am just messing around with the new raycasting (The old raycasting: FindPartOnRayWithIgnoreList(), the new one: Rascast())

PS: Thank you to everyone that is going to answer
PS 2: I might not respond immediately, it’s nearly 12 AM for me and I want some sleep

1 Like

My advise to show all code so we can see the implementation and definition, because here it implies that the parameter is nil


The ray doesn’t hit anything. That’s why you are getting an error.
Try doing:

if raycatResult then

Local script (Is inside the StarterCharacterScripts)


local player = game.Players.LocalPlayer
local character = player.Character

local rayDistance = 5
local yAmountToTake = 1

-- Setting raycast params
local raycastParams =
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.IgnoreWater = true
local tableToIgnore = {}
for i, object in pairs(character:GetChildren()) do
	if object:IsA("Part") then
		table.insert(tableToIgnore, object)
raycastParams.FilterDescendantsInstances = tableToIgnore


while wait(0.01) do
	local newTorsoPosition =,
		character.Torso.Position.y - yAmountToTake, 
	local raycastResult = 
	if (raycastResult ~= nil) then

Main Script (Inside the ServerScriptStorage)

-- Variables --

-- Functions --

local function CreateRay(raycastResult,newCharacterTorsoPos)
	local distance = (newCharacterTorsoPos - raycastPosition.Position)
	local part ="Part")
	part.Transparency = 0.5
	part.CanCollide = false
	part.Anchored = true
	part.Material = Enum.Material.Neon
	part.BrickColor ="Neon orange")
	part.Size =,0.3,distance)
	part.CFrame =,raycastPosition.Position) *,0,-distance / 2)
	part.Parent = game.Workspace.Rays

-- Events --

game.ReplicatedStorage.Remotes:WaitForChild("MakePart").OnServerEvent:Connect(function(plr, raycastResult,characterTorsoPos)

I pasted the code. I am checking if the code is nil, so that’s definitely not the case. Any more ideas?