I’m trying to make a gun with raycasting, and I’m using a remote event to do it. I send the parameters of the position of the players head and the mouse’s position from the client, but for some reason, on the server, the parameter that should be the player character’s head is just the player instance?
Here’s the code sending the info:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Mouse = game:GetService("Players").LocalPlayer:GetMouse()
local Player = Players.LocalPlayer
local rayOrigin
local rayDirection
local Folder = ReplicatedStorage.Guns.Revolver.Attack
local CoolDown = 1
Mouse.Button1Down:Connect(function()
rayOrigin = Player.Character.Head
rayDirection = Mouse.Hit.Position
print(rayOrigin)
Folder.Fire:FireServer(rayOrigin, rayDirection, Player.Character)
end)
Here’s the code that receives the info:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local raycastParams
local raycastResults
local Folder = ReplicatedStorage.Guns.Revolver.Attack
Folder.Fire.OnServerEvent:Connect(function(raycastStart, raycastDirection, PlayerCharacter)
raycastParams = RaycastParams.new()
-- raycastParams.FilterDescendantsInstances = {PlayerCharacter}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.IgnoreWater = true
print(raycastStart)
raycastResults = workspace:Raycast(raycastStart.Position, raycastDirection)
print(raycastResults)
end)
As you can see in the code, I already tried printing the raycast start on both the client and the server to see why it wasn’t working. That’s how I figured out the problem. I haven’t really tried much else because I have no idea how I could possibly fix this.