Can't pass Mouse.Hit on server script

I’ll simplify my script to this :

local target = FindNearest(script.Parent.HumanoidRootPart.Position)
cf = mouse.Hit
WormholeEvent:FireServer(target, cf)

The matter here is that the server script will show an error saying that the cf value is nil, which is obviously not. This script part is in a local script in the player’s character, it works well there as I can print the mouse position, but it doesn’t pass to the server script for some reason.

1 Like

You are not defining what “mouse” means. You need to define “mouse” so the script knows what you are talking about.

1 Like

Sorry I did not show it, but the mouse is defined in the local script as

local mouse = player:GetMouse()

As I said, I can get the value just fine in the local script.

1 Like

If the cf value is nil, it probably means mouse.Hit == nil.

1 Like

mouse.Hit can never be nil. It will always point to a CFrame. It is likely something else that is wrong.

@ OP can you show a bit more code (like the server code, your OnServerEvent listener parameters are probably set up wrong)

1 Like

Here’s a bit of the server script, it errors when setting wormhole2’s position
Also, whether it’s wormhole2.Position or wormhole2.CFrame, the result is the same, I print position before and the result is nil

function Wormhole(player, position)

local IdleTrack = player.Character.Humanoid:LoadAnimation(player.Character.HumanoidRootPart.Idle)
print(position)
player.Character.HumanoidRootPart.Anchored = true
IdleTrack:Play()
wormhole = ReplicatedStorage.Characters.Johnny.WormholeModel:Clone()
wormhole2 = ReplicatedStorage.Characters.Johnny.WormholeModel:Clone()

wormhole2.Position = position
wormhole.CFrame = player.Character.HumanoidRootPart.CFrame*CFrame.new(0,-4,-3)* CFrame.Angles(math.rad(90), 0, 0)
wormhole.Parent = player.Character
wormhole2.Parent = player.Character
1 Like

Mouse.Hit is a CFrame value, not a Vector3. So send over mouse.Hit.Position instead from the LocalScript.

1 Like

Whether I send hit or hit.position I get this : image

1 Like
WormholeEvent:FireServer(target, cf)

Then whatever target is, is nil. Remove it from your argument list and only send cf.Position over.

1 Like

Alright I’m an idiot, I forgot I’m not using the target argument in the server script…

1 Like