Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My bullet does not start at bullet point, instead it starts farther away from the bulletpoint?

Asked by 3 years ago

Heres a demonstration: ![Image from Gyazo](https://i.gyazo.com/3b362dd1b9da3a79637c9e1f91bc9e71.gif)

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.

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)




Answer this question