Why is raycastResult returning nil?

having a problem with raycasting (im pretty new to it lol)
trying to create a raycast that makes a trajectory on the server
when i try to deliver the raycasting result, it passes if rayresult then however returns nil on the server
am i doing smth wrong?

module script

		local head = player.Character.Head.CFrame.LookVector
		local mouse = CFrame.new(player.Character.Head.Position, mouse.Hit.Position).LookVector
		local difference = (head-mouse)
		self.Viewmodel.Gun.PrimaryPart.Muzzle.Flash:Emit(10)
		self.Viewmodel.Gun.PrimaryPart.Chamber.Casings:Emit(1)
		local raycastParams = RaycastParams.new()
		raycastParams.RespectCanCollide = true
		raycastParams.FilterDescendantsInstances = {self.Viewmodel:GetChildren(), player.Character}
		local rayresult = workspace:Raycast(self.Viewmodel.Gun.PrimaryPart.Muzzle.WorldCFrame.Position, (player:GetMouse().Hit.Position - self.Viewmodel.Gun.PrimaryPart.Muzzle.WorldCFrame.Position).unit * 300, raycastParams)
		if rayresult then
			remotes.Gunfire:FireServer(self.Tool, rayresult)
			player.Character.Humanoid.WalkSpeed = player.PlayerGui["Realism Mod"].Sprint.Settings["Walking speed"].Value
		end

server script starting loop

remotes.Gunfire.OnServerEvent:Connect(function(player, tool, raycastResult)

You didnt create an else statement for the rayresult.

Are you using the module script from the client then sending it to the server? If so, the raycast only exists on the client, therefore it wouldn’t replicate to the server. That means you’ll have to use the module script from the server.

scheduling a doctor’s appointment for my brain later thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.