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!
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)