This is a fastcast gun and I dont know if it affects my problem or it has something to do with it. I had tried moving my attachment backwards and backwards but still very far away from the bullet point. I don't know if it's from the attachment or what. I would likely appreciate if you answer my question. This is the third time I had reposted this question and this problem had been over 3 or 4 days and not yet been solved, please answer, it would likely help.
Update: I saw that my velocity was the problem, but I want my bullets to be fast not slow. How can I fix this problem? I know that phantom forces, arsenal, etc did a great job at doing this.
Client:
gun.Activated:Connect(function()
if bullets.Value > 0 then
shooting = true
while shooting do
wait(0.1)
bullets.Value = bullets.Value - 1
player.PlayerGui.AmmoGui.Ammo.Text = "" .. tostring(bullets.Value) .. " / " .. tostring(ammo.Value)
gunshot:Play()
remoteevent:FireServer(mouse.Hit.Position) --remote event
gun.Deactivated:Connect(function()
shooting = false
end)
if bullets.Value <= 0 then
break
end
end
end
end)
Server:
local RNG = Random.new()
local gun = script.Parent
local remoteevent = gun.clientserver
local fastcast = require(gun.FastCastRedux)
local caster = fastcast.new()
local Firepoint = gun.Handle.Attachment
local MIN_BULLET_SPREAD_ANGLE = 1
local MAX_BULLET_SPREAD_ANGLE = 10
local bulletsFolder = workspace:WaitForChild("BulletFolder") or Instance.new("Folder", workspace)
bulletsFolder.Name = "BulletFolder"
local bulletTemplate = game.ServerStorage.BulletKill:Clone()
bulletTemplate.Parent = bulletsFolder
local function onrayhit(cast, result, velocity, bullet)
bullet:Destroy()
local hitpart = result.Instance
local hitpoint = result.Position
local normal = result.Normal
local character = hitpart:FindFirstAncestorWhichIsA("Model")
if character and character:FindFirstChild("Humanoid") then
character.Humanoid:TakeDamage(15)
end
game.Debris:AddItem(bullet, 4)
end
-- Scroll Down
local function onlengthchanged(cast, lastpoint, direction, length, velocity, bullet)
if bullet then
local bulletlength = bulletTemplate.Size.Z/2
local offset = CFrame.new(0,0,-(length - bulletlength))
bullet.CFrame = CFrame.lookAt(lastpoint, lastpoint + direction):ToWorldSpace(offset)*CFrame.Angles(0,math.rad(-90),0)
end
end
local castParams = RaycastParams.new()
castParams.FilterType = Enum.RaycastFilterType.Blacklist
castParams.IgnoreWater = true
local castBehavior = fastcast.newBehavior()
castBehavior.RaycastParams = castParams
castBehavior.Acceleration = Vector3.new(0, -200, 0)
castBehavior.AutoIgnoreContainer = false
castBehavior.CosmeticBulletContainer = bulletsFolder
castBehavior.CosmeticBulletTemplate = bulletTemplate
local function onequipped()
castParams.FilterDescendantsInstances = {gun.Parent, bulletsFolder}
end
local function fire(player,mousePos)
game.Workspace.BulletFolder.BulletKill.Attacker.Value = player.Name
local origin = Firepoint.WorldPosition -- This is the exact position
local direction = (mousePos - origin).Unit
caster:Fire(origin, direction, 1000, castBehavior)
end
gun.Equipped:Connect(onequipped)
remoteevent.OnServerEvent:Connect(fire)
caster.LengthChanged:Connect(onlengthchanged)
caster.RayHit:Connect(onrayhit)

