Hey, QueuedUsername, here. Recently, I’ve just learned of AnimationEvents and the GetMarkedReachedSignal()
function. I’ve created a reloading function for my gun involving a ejection function I’ve made. But every time I reload the weapon, the part that is ejected is added by another copy.I don’t understand what’s going on, I’m simply looking for an error or issue I’ve made in my code.
elseif currentFiringMode == 'BOLT_ACTION' then -- Ignore this statement
if moduleRequired.MAG_CAPACITY ~= moduleRequired.MAG_CONSTANT then
while moduleRequired.MAG_CAPACITY ~= moduleRequired.MAG_CONSTANT and moduleRequired.RSRV_CAPACITY > 0 do
moduleRequired.MAG_CAPACITY = moduleRequired.MAG_CAPACITY + 1
moduleRequired.RSRV_CAPACITY = moduleRequired.RSRV_CAPACITY - 1
gui.Frame.Counter.Text = '...'
end
end
if reloadT then reloadT:Play() reloadT:GetMarkerReachedSignal("EjectPart"):Connect(function() EjectCasing(tool.StripPiece, tool.EjectionPart2, 1) end) end
end
Reload Function
function EjectCasing(partToClone, partToEjectFrom, noOfCasings)
for i = 1, noOfCasings do
local shell = partToClone:Clone()
shell.Transparency = 0
shell.Name = 'Casing_Clone'
shell.Parent = workspace
shell.CFrame = partToEjectFrom.CFrame
shell.CanCollide = true
shell.Velocity = partToEjectFrom.CFrame.LookVector * moduleRequired.VELOCITY
shell.RotVelocity = partToEjectFrom.CFrame.LookVector * moduleRequired.ROT_VELOCITY
game:GetService('Debris'):AddItem(shell, .8)
end
end
Part Ejection Function
Animation
End Result
If you need extra screenshots, send me a comment below! Thanks for reading!