I’m trying to create a raycast from the player’s character to the camera’s LookVector on the server side. I’m currently sending the LookVector over a remote event.
Client side:
local LookVector = workspace.CurrentCamera.CFrame.LookVector
local function onButton1Down()
Remote:FireServer(LookVector)
end
mouse.Button1Down:Connect(onButton1Down)
Server side:
Remote.OnServerEvent:Connect(function(LookVector)
local length = 1000
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {player}
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.IgnoreWater = true
local raycastResult = workspace:Raycast(Root, LookVector * length, Params)
end)
Root is the humanoid root part.
I’m getting this error: attempt to perform arithmetic (mul) on Instance and number
I still get the same error when defining it within the function:
local function onButton1Down()
local LookVector = workspace.CurrentCamera.CFrame.LookVector
Remote:FireServer(LookVector)
print("sent input to the server")
end
Make sure you adjusted your function to include the player as the first value!
Right now your LookVector variable is being set to the player, which is why it gives the Unable to cast Instance to Vector3 error.
Remote.OnServerEvent:Connect(function(player, LookVector)
local length = 1000
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {player}
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.IgnoreWater = true
local raycastResult = workspace
end)
I am already passing player as the first value and still getting this error, as I mentioned in my last message.
Anyways the player is sent over automatically without having to define it in the remote. When I define both the player and the look vector on the server side, I receive my original error:
Client side:
local function onButton1Down()
local LookVector = workspace.CurrentCamera.CFrame.LookVector
Remote:FireServer(player, LookVector)
print("sent input to the server")
end
Server side:
Remote.OnServerEvent:Connect(function(player, LookVector)
local length = 1000
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {player}
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.IgnoreWater = true
local raycastResult = workspace:Raycast(Root, LookVector * length, Params) -- this line is causing the error according to the output
end)
Error: attempt to perform arithmetic (mul) on Instance and number
local function onButton1Down()
local LookVector = workspace.CurrentCamera.CFrame.LookVector
Remote:FireServer(LookVector)
print("sent input to the server")
end
Remote.OnServerEvent:Connect(function(player, LookVector)
local length = 1000
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {player.Character}
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.IgnoreWater = true
local raycastResult = workspace:Raycast(Root, LookVector * length, Params) -- this line is causing the error according to the output
end)
The only issue seems to be that you are not assigning the “Player” variable in the OnServerEvent function. You’re code logic seems quite fine other than that.
Ima start testing in roblox studio and see if I can find something, brb.
EDIT: Allright, this code works for me:
Client:
local function onButton1Down()
local LookVector = workspace.CurrentCamera.CFrame.LookVector
Remote:FireServer(LookVector)
end
mouse.Button1Down:Connect(onButton1Down)
Server:
Remote.OnServerEvent:Connect(function(player, LookVector)
local length = 1000
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {player.Character}
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.IgnoreWater = true
local raycastResult = workspace:Raycast(Root.Position, LookVector * length, Params)
end)