

You can pre-make yours, which I already have. Logically, if the ray doesn’t hit anything, the “hit position” is origin + direction. So that is what the result and result.Position or origin + direction*300 is for, since I am pretty sure even if the player doesn’t click on anything you would want a bullet to be shot nonetheless. Local intersection = result and result.Position or origin + direction*300 WorldRoot:Raycast returns nil if the ray cast didn’t hit anything. So here we are just getting the direction of the shoot part position and the mouse position, and extending it for 300 studs since that is what the old tutorial did, although of course you can extend it further or even decrease it.

Local result = Workspace:Raycast(shoot_part.Position, direction*300) Local direction = (position - origin).Unit Local ServerStorage = game:GetService("ServerStorage") Remote.OnServerEvent:Connect(function(player, position) Local Workspace = game:GetService("Workspace")

Local shoot_part = tool:WaitForChild("Shoot") no im not using the built-in one but you can if you want local tool = script.Parent I will also declare a variable for Workspace, in addition to one for the Shoot part from the tool. So I am going to steal some variables from the frontend script and connect to OnServerEvent. Then in the backend script you will want to listen for the OnServerEvent event of the OnShoot remote. Now we will want to listen for the tool’s Activated event and just fire the remote with the mouse’s position: local tool = script.Parent If you would like to learn how to get the hit position, have a look at this reply of mine, position is either result and result.Position or origin + direction.īut for simplicity’s sake I will just use the legacy mouse. It isn’t a full replacement though unfortunately due to some restrictions. So I have made this (which exposes PlayerMouse2.Position) as a modern alternative. The vanilla mouse is legacy, and is likely to be deprecated in the future. While I don’t like advertising my own stuff I have made a custom mouse module. Local Players = game:GetService("Players") Local remote = tool:WaitForChild("OnShoot") Image 266×503 13.6 KB Coding the frontendįirst I will declare some variables.
