So I know that it really easy to script guns and I thought I'd make something like a turret. But then I realized, that I'm going to need a regular script, not a local script to script the turret. Is there any way for me to make a model that shoots when ever mouseclicked? And can you teach me how to make it so the bullet goes in the direction of the mouse? Thank you!
COMMUNITY QUESTION
Is it possible to make bullets using a regular script, not a local script?
1 answer
You'll need to have your bullet inside of ReplicatedStorage. Make sure it's one singular model/mesh, that way it's easier to script, and you don't have to get the hard parts of moving a model. Next, you'll need to type this script:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local part = game.ReplicatedStorage:WaitForChild("bulletname")
local startPoint = part.CFrame.p -- This will be the firing point basically
local speed = 100
mouse.Button1Down:connect(function()
local lookPoint = mouse.Hit.p
local projectile = Instance.new("Part") -- Creating the projectile (I'm pretty sure you know how to edit it by using Instance.new with a mesh and configuring it.)
projectile.Parent = workspace
projectile.CFrame = CFrame.new(startPoint,lookPoint) -- Projectile starts at "startPoint", while looking at "lookPoint"
mouse.TargetFilter = projectile -- The mouse will ignore the projectile so it doesn't end up above the mouse position
local BV = Instance.new("BodyVelocity") -- Creating body velocity
BV.Parent = projectile -- parenting it to the projectile
BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge) -- Setting max speed
BV.Velocity = projectile.CFrame.lookVector * speed -- It will fly in the direction the projectile is facing multiplied by the Speed
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

8 comments
just a question, isn't local player used for local scripts?
Technically. But whilst also running this, you can use RemoteEvents to fire a server event through a localscript. Which will basically do the same moving bullet.
You can learn more about RemoteEvents here: https://developer.roblox.com/en-us/api-reference/class/RemoteEvent
So I'm first gonna have to create a bullet, and add it to restorage? Or will the script create the bullet and all? Second thing, in your preivious comment, you said local player can be used for local scripts. Can it also be used for server scripts? So is this a local, or server script?
This is a LocalScript. You'll use remote events to create :FireServer() through the localscript, which in another script, will receive the fire through OnServerEvent. In that other script, you'll type the code that makes the bullet move, so that way, it's server-sided.
If you're wondering what type the other script will be, try both to see which works.
well ill do remote event tutorials then
it wasn't working. I suspect its because something I did wrong. I sent you photos, plz help.