Hey, so I’m working on a fps and I’ve came across this issue, the bullet isn’t cast until the apex of the gun animation. Here is a video to show you:
Fire function:
local function fire(toFire,gunName)
if equipping then return end
if reloading then return end
if not player.Character then return end
if toFire and ammo[currentViewmodel.values.Slot.Value].ammo <= 0 then firing = false end
if not canFire and toFire then return end
firing = toFire
if not toFire then return end
local function shoot()
if ammo[currentViewmodel.values.Slot.Value].ammo <= 0 then return end
local sound = currentViewmodel.fireSound:Clone()
sound.Parent = currentViewmodel
sound:Play()
game:GetService("Debris"):AddItem(sound,5)
local anim = currentViewmodel.animControl:LoadAnimation(currentViewmodel.clientAnimations.fire)
anim:Play()
ammo[currentViewmodel.values.Slot.Value].ammo -= 1
player.PlayerGui.ammoGui.backG.ammoCounter.Text = ammo[currentViewmodel.values.Slot.Value].ammo.." / "..ammo[currentViewmodel.values.Slot.Value].max
recoil:shove(Vector3.new(0.03,0,0 * deltaTime * 60))
spawn(function()
wait(0.15)
recoil:shove(Vector3.new(-0.02,0,0) * deltaTime * 60)
end)
local origin = currentViewmodel.barrel.barrelAttachment.WorldPosition
local direction = currentViewmodel.barrel.barrelAttachment.WorldCFrame
fastCastHandler:Fire(origin,direction)
wait(60/currentViewmodel.values.RPM.Value)
end
repeat
canFire = false
shoot()
canFire = true
until ammo[currentViewmodel.values.Slot.Value].ammo <= 0 or not firing or reloading
if reloading then firing = false end
if ammo[currentViewmodel.values.Slot.Value].ammo <= 0 then firing = false canFire = true end
end
Where the function is fired:
uis.InputBegan:Connect(function(key,gpe)
if gpe then return end
if key.UserInputType == Enum.UserInputType.MouseButton1 then
fire(true,curEquipped)
end
end)
And the FastCast handler:
function fastCastHandler:Fire(origin,direction,properties,IsReplicated,repChar)
local rawOrigin = origin
local rawDirection = direction
local directionalCFrame = CFrame.new(Vector3.new(),direction.lookVector)
direction = (directionalCFrame * CFrame.fromOrientation(0,0,random:NextNumber(0,math.pi * 2)) * CFrame.fromOrientation(0,0,0)).LookVector
local bullet = rs.bullet:Clone()
bullet.CFrame = CFrame.new(direction,origin + direction)
bullet.Parent = workspace.fastCast
bullet.Size = Vector3.new(0.05, 0.05, 1200/200)
local id = math.random(-10000,10000)
local idValue = Instance.new("NumberValue")
idValue.Name = "id"
idValue.Value = id
idValue.Parent = bullet
bullets[id] = {
Properties = properties,
replicated = IsReplicated
}
if not IsReplicated then
gunRemotes.fire:FireServer(rawOrigin,rawDirection,id)
end
local list = {
workspace.Camera,
workspace.CurrentCamera,
players.LocalPlayer.Character,
players.LocalPlayer.Character.HumanoidRootPart
}
mainCaster:FireWithBlacklist(origin,direction * 5000, 200, list, bullet, true, Vector3.new(0,rs.gravity.Value,0))
end
Everything works, no errors, it’s just the problem described at the top of the post.
Thanks in advance!