Hey, this is my first post but anyway, straight to the point cause I don’t wanna waste people’s time,
I’m making a script to duplicate the mag of a weapon for a more immersive reload, it works, (in the sense that it clones the mag) but once you reload twice, it will clone it twice, if you reload three times, it will clone three times and so on.
Here’s the script:
local Created = false
if Created == false then
Created = true
local MagClone = Fake.Magazine:Clone()
MagClone.Parent = workspace
MagClone.CFrame = Fake.Magazine.CFrame
MagClone.Anchored = false
MagClone.CanCollide = true
Created = false
end
Sorry if this is very simple and I’m just being oblivious, or if I’m leaving important code out. Thank you for reading.
1 Like
I need to see the rest of the code to determine the issue. I have had the same issue before and I want to confirm the situation before I give you an answer
The rest of the code is 1726 lines long though
I just need to see what activates it the clone function. Did you forget to delete the mag after the animation is done?
Oh I see, well here you go:
if ActuallyEquipped then
if Module.TacticalReloadAnimationEnabled then
if Mag > 0 then
if TacticalReloadAnim then TacticalReloadAnim:Play(nil,nil,Module.TacticalReloadAnimationSpeed) end
if VMTacticalReloadAnim then VMTacticalReloadAnim:Play(nil,nil,Module.VMTacticalReloadAnimationSpeed) end
Handle.TacticalReloadSound:Play()
VMTacticalReloadAnim:GetMarkerReachedSignal("MagDuplicate"):Connect(function()
local Created = false
if Created == false then
Created = true
local MagClone = Fake.Magazine:Clone()
MagClone.Parent = workspace
MagClone.CFrame = Fake.Magazine.CFrame
MagClone.Anchored = false
MagClone.CanCollide = true
Created = false
end
end)
Hope this helps, let me know if you need more code.
Add a print function to see how many times the clone gets fired. Just type print(“fired”) after local magclone = mag:Clone()
Alright, I’ll test that, also I didn’t see that last bit and yes I did make it delete the mag after a couple seconds, and it just deleted all the mags at the same time.
Edit: Just tested it, and like I thought it fires the same amount as the times you’ve reloaded. so if I reload twice, it fires twice.
Edit: I figured out a solution, It’s a pretty weird one but what I did was I would play a sound whenever the mag is duplicated, and used whether or not it was playing as a debounce, because the normal debounce wasn’t working. Thank you for your help!
1 Like