Pls read this topic carefully as most gun scripts are activate by players(
I want the gun to autofire constantly…
Pls read this topic carefully as most gun scripts are activate by players(
I want the gun to autofire constantly…
Are you wanting to code a gun from scratch or do you want to modify an existing gun?
It is based on whether the code is helpful in my script, for now i am trying to create my own script…
probably going to be at least 100 lines
model is probably going to be borrowed because it is too hard to do the modelling for a solo developer…
Decent guns are going to be way more than 100 lines, depending on how many features it has.
Most existing gun codes should be modifiable to make it so it automatically shoots, so I would recommend just using an existing one and modify it. If you decide on one, let us know and provide the source code of it so we can help you modify it.
Ok Thanks for helping i will ask u if there are some modifying…
I am not bad at scripting so it should work…
I have finally done the automatic gun Script
local cooldown = 2 -- the time interval for shooting
local Speed = 200 -- Change the speed of the part
local MaxAmmo = 100 -- Change this
local Ammo = MaxAmmo
local Handle = script.Parent.Handle
local Main = script.Parent.Main
local Camera = game:GetService("Workspace").CurrentCamera
local Functions = require(script.Parent.Modules.Functions)
local Debris = game:GetService("Debris")
--FiringOffset = Vector3.new(0, ((Handle.Size.Y / 4) - 0.2), -(Handle.Size.Z / 2))
--Sounds
local Fire = Handle.Fire
local NoAmmo = Handle.NoAmmo
local Reload = Handle.Reload
--Position Of The final Part
local FiringOffset = Vector3.new(0, ((Handle.Size.Y / 4) - 0.2), -(Handle.Size.Z / 2))
local function FireAtivation(StartPosition, TargetPosition, Part, SpawnPosition )
local Character = nil
local Direction = CFrame.new(StartPosition, TargetPosition).lookVector
local RayHit, RayPos, RayNormal = Functions.CastRay(StartPosition, Direction, 2048, {Character}, false)
local Attachement = Instance.new("Attachment", Part)
local LinearVelocity = Instance.new("LinearVelocity", Attachement)
LinearVelocity.MaxForce = math.huge
LinearVelocity.VectorVelocity = Direction * Speed
LinearVelocity.Attachment0 = Attachement
--wait((Distance / 80)
local Distance = Direction.magnitude
local PX = (StartPosition + (0.0 * Distance) * Direction)
local PY = (StartPosition + (0.0 * Distance) * Direction)
local PZ = (StartPosition + (0.0 * Distance) * Direction)
local DX = (StartPosition - PX).magnitude
local DY = (PX - PY).magnitude
local DZ = (PY - PZ).magnitude
local Limit = 2
local AX = (PX + Vector3.new(math.random(math.max(-Limit, (-0.0 * DX)), math.min(Limit, (0.21 * DX))),math.random(math.max(-Limit, (-0.21 * DX)),math.min(Limit, (0.21 * DX))), math.random(math.max(-Limit, (-0.21 * DX)), math.min(Limit, (0.21 * DX)))))
local AY = (PY + Vector3.new(math.random(math.max(-Limit, (-0.0 * DY)), math.min(Limit, (0.21 * DY))),math.random(math.max(-Limit, (-0.21 * DY)),math.min(Limit, (0.21 * DY))), math.random(math.max(-Limit, (-0.21 * DY)), math.min(Limit, (0.21 * DY)))))
local AZ = (PZ + Vector3.new(math.random(math.max(-Limit, (-0.0 * DZ)), math.min(Limit, (0.21 * DZ))),math.random(math.max(-Limit, (-0.21 * DZ)),math.min(Limit, (0.21 * DZ))), math.random(math.max(-Limit, (-0.21 * DZ)), math.min(Limit, (0.21 * DZ)))))
local Rays = {
{Distance = (AX - StartPosition).magnitude, Direction = CFrame.new(StartPosition, AX)},
{Distance = (AY - AX).magnitude, Direction = CFrame.new(AX, AY)},
{Distance = (AZ - AY).magnitude, Direction = CFrame.new(AY, AZ)},
{Distance = (TargetPosition - AZ).magnitude, Direction = CFrame.new(AZ, TargetPosition)},
}
local AttackArea = game.ReplicatedStorage.PlayerParts.PlayerTouched.PlayerTouchedPart:Clone() -- This is your own Part
--AttackArea.Size = Vector3.new(10,2,10)
--print(AttackArea.CFrame)
AttackArea.BrickColor = BrickColor.new("Bright red")
AttackArea.Reflectance = 0.4
AttackArea.Transparency = 0.5
AttackArea.CanCollide = false
AttackArea.Anchored = true
AttackArea.Parent = game.Workspace.Cabins.FromCabin16Onwards["Cabin16-35"].Cabin20.StorageParts -- put the part in a folder
AttackArea.CFrame = CFrame.new(SpawnPosition) + Vector3.new(0,3,0)
Debris:AddItem(AttackArea, 0.6)
for i, v in pairs(Rays) do
local Ray = Part:Clone()
Ray.BrickColor = BrickColor.new("Bright red")
Ray.Reflectance = 0.4
Ray.Transparency = 1 --1
Ray.CFrame = (v.Direction * CFrame.new(0, 0, (-0.5 * v.Distance)))
Debris:AddItem(Ray, (0.1 / (#Rays - (i - 1))))
Ray.Parent = Camera
end
end
local Configuration = script.Parent.Configuration
local StartPosition = (Handle.CFrame * CFrame.new(FiringOffset.X, FiringOffset.Y, FiringOffset.Z)).p
local function FireBullet(bulletPosition, bulletName)
local Xpos = math.random(240, 315.1) -- Your PositionX(Randomized)
local Ypos = math.random(0.166, 0.5) -- Your PositionY(Randomized)
local Zpos = math.random(-455.7, -400) -- Your PositionZ(Randomized)
local TargetPosition = Vector3.new(Xpos,Ypos,Zpos)
local SpawnPartPosition = TargetPosition
local TargetPosition = {Position = bulletPosition, Target = TargetPosition}
TargetPosition = TargetPosition.Position
local Accuracy = (Configuration.Accuracy.Value * 100)
TargetPosition = TargetPosition + Vector3.new((math.random(-Accuracy.X, Accuracy.X) * 0.01), (math.random(-Accuracy.Y, Accuracy.Y) * 0.01), (math.random(-Accuracy.Z, Accuracy.Z) * 0.01))
--Configuration.Ammo.Magazines.Value = (Configuration.Ammo.Magazines.Value - 1)
FireAtivation(StartPosition, TargetPosition, bulletName, SpawnPartPosition)
end
local function BulletCreate()
Fire:Play()
local bullet = Instance.new("Part")
bullet.Parent = game.Workspace.Cabins.FromCabin16Onwards["Cabin16-35"].Cabin20.StorageAmmo
bullet.Position = Handle.Position
bullet.Size = Vector3.new(2,1,1)
bullet.BrickColor = BrickColor.new("Really red")
bullet.Shape = Enum.PartType.Block
bullet.CollisionGroup = "Bullet"
bullet.CanCollide = true
bullet.Material = Enum.Material.Neon
bullet.Name = "Bullet"
bullet.CFrame = script.Parent.BulletSpawn.CFrame
Debris:AddItem(bullet, 0.55)
--local StartPosition = (Handle.CFrame * CFrame.new(FiringOffset.X, FiringOffset.Y, FiringOffset.Z)).p
FireBullet(bullet.Position, bullet)
end
while true do
repeat
task.wait(0.12)
Ammo -= 1
BulletCreate()
until Ammo == 0
Fire:Stop()
Reload:Play()
Ammo = MaxAmmo
task.wait(cooldown)
~~~
This is the automatic bullet fire script and it works!!!