Problems with RemoteEvent

I’m trying to make a custom laser gun and to use LocalScript for detecting inputs and ServerScript for firing the laser. However I got an error whenever I fire the gun: attempt to index nil with 'Instance'

LocalScript

tool=script.Parent
handle=tool:WaitForChild('Handle')
shoot=tool:WaitForChild('Shoot')
-- other code
function initialShoot(part, params)
	local point=handle:WaitForChild('StartingPoint')
	local direction=point.CFrame:PointToObjectSpace(part.Position)
	local result=workspace:Raycast(
		point.WorldPosition,
		direction,
		params
	)
	
	if result ~= nil then
		shoot:WaitForChild('Activate'):FireServer(part,result)
	end
end
-- other code

ServerScript

tool=script.Parent
handle=tool:WaitForChild('Handle')
event=script:WaitForChild('Activate')
players=game:GetService('Players')
-- other code
event.OnServerEvent:Connect(function(player, part, result)
	local character=part.Parent
	local target=players:GetPlayerFromCharacter(character)
	if target then
		if target~=player and result.Instance==part then -- WHERE IT ERRORS
			local humanoid=character:WaitForChild('Humanoid')
			humanoid.Health-=25
		end
	-- other code
end

Hireachy
image

Either the RaycastResult is nil or the RemoteEvent is having issues passing the arguments. But I made sure if RaycastResult is nil then it won’t fire the event. Any ideas?

Try adding prints, print what what the client sends to the server and print what the server receives. It is a very good way to figure out what is going wrong.

The RemoteEvent just won’t send the RaycastResult so I manually send it’s properties instead, thanks regardless!

RaycastResult objects do not replicate across the client-server boundary (in either direction), so as you did, you need to serialize the object first before transferring it across the network via a network object (RemoteEvent, RemoteFunction etc.).