Because my gun system work with a script and a localscript
The raycast is happening on the server script, the local script is just firing the remote event
I’m just trying to problem solve. I have an itch about why this is happening, and if you don’t solve it, you’re going to have some trouble. my animation is the Ud’zal animation. and sometimes, when I’m idle, I literally bend down and look around. If you shoot the gun while standing still, it would be slightly inaccurate, and not from the camera.
I understand that i need to start the raycast from the camera but explain me how, you tell me to manage the raycast from the client but doing that is not safe from exploiters
yeah, but my best suggestion is to do this. @Den_vers makes a very good point about the gun.
if you’re using mouse.hit.p you must be using a localscript right?
local origin = workspace.CurrentCamera.CFrame
local direction = workspace.CurrentCamera.CFrame.LookVector
You don’t, you can either send the camera position to the server, which I don’t recommend, or just cast from position above the humanoid root part. Automatically casting from the server will have it’s cons, because there is an automatic delay between the client and server.
I take the mouse.hit.position from the client then send it to the server that is referenced as “mousePosition”
Local side
Server side
If you’re already sending the mouseposition, you might as well send the camera position.
I can’t put CFrame values in these
I have come across this problem before and solved it. Since caster requires a raycast direction, in the local script, you’ll have to put in a raycast from the camera, straight.
First you have to check whether the device is mobile like so:
if UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled and not UserInputService.MouseEnabled and not UserInputService.GamepadEnabled then
Mobile = true
else
Mobile = false
end
Then, you have to write an if statement if Mobile
if Mobile then
local RayCastParameters = RaycastParams.new()
RayCastParameters.FilterDescendantsInstances = {Character:GetChildren(), Tool:GetChildren()}
RayCastParameters.FilterType = Enum.RaycastFilterType.Blacklist
local RayCast = workspace:Raycast(Camera.CFrame.Position, Camera.CFrame.LookVector * 10000, RayCastParameters)
print(RayCast.Position)
fireEvent:FireServer(RayCast.Position)
else
fireEvent:FireServer(mouse.Hit.Position)
end