Gun won't reload

  1. What do you want to achieve? Keep it simple and clear!

I want to make an old gun FE compatible, and also be able to reload

  1. What is the issue? Include screenshots / videos if possible!

The gun can’t reload. The original, old gun was able to reload (but broken damage)


  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried looking at other fixed old guns, I was only able to fix the firing.

I have 2 scripts: FEScript

function Reload()
	Tool.Ammo.Value = Tool.MaxAmmo.Value
	if script.Parent.Ammo.Value < script.Parent.MaxAmmo.Value and reloading == false and script.Parent.StoredAmmo.Value >= 1 then
		reloading = true
		script.Parent.Ammo.Value = 0
		ShellInsert()
		script.Parent.StoredAmmo.Value = script.Parent.StoredAmmo.Value + script.Parent.Ammo.Value
		if script.Parent.StoredAmmo.Value >= script.Parent.MaxAmmo.Value then
			script.Parent.StoredAmmo.Value = script.Parent.StoredAmmo.Value - script.Parent.MaxAmmo.Value
			script.Parent.Ammo.Value = script.Parent.MaxAmmo.Value
		elseif script.Parent.StoredAmmo.Value < script.Parent.MaxAmmo.Value and script.Parent.StoredAmmo.Value >= 1 then
			script.Parent.Ammo.Value = script.Parent.StoredAmmo.Value 
			script.Parent.StoredAmmo.Value = 0
		end
		reloading = false
	end
end

And also Shooter (LocalScript)

Tool = script.Parent
FEScript = Tool:WaitForChild("FEScript")

local reloading = false
local canclereloading = false

function Reload()
	reloading = true
	FEScript.ReloadGun:FireServer()
	reloading = false
end

These aren’t the full scripts. Also ts is my first time here

1 Like

if my braincells are working rn from what i see the tool’s ammo is immediately being set to the maximum so the precondition if statement never runs, so the actual StoredAmmo value never gets updated and no shell inserts happen, so just remove the first line in the reload function

spoon feed
function Reload()
	Tool.Ammo.Value = Tool.MaxAmmo.Value
	if ...
end

to

function Reload()
	if ...
end
1 Like

Well it still didn’t reload, BUT it did reload when I accidentally made the Ammo value less than MaxAmmo, for example Ammo = 8, MaxAmmo = 10. But it only reloads one shell, and it doesnt work anymore

because that’s what the code does

the code isn’t in a loop, so it’ll run ocne and stop

1 Like

i’ve refactored and edited the code a little bit to the best of my ability, maybe it’ll fix it since it is pretty old

function Reload()
	if script.Parent.Ammo.Value < script.Parent.MaxAmmo.Value and not reloading and script.Parent.StoredAmmo.Value >= 1 then
		reloading = true

		local neededAmmo = script.Parent.MaxAmmo.Value - script.Parent.Ammo.Value
		local availableAmmo = script.Parent.StoredAmmo.Value
		local ammoToReload = math.min(neededAmmo, availableAmmo)

		script.Parent.StoredAmmo.Value -= ammoToReload
		script.Parent.Ammo.Value += ammoToReload

		ShellInsert()
		reloading = false
	end
end

Okay I got a script that can finally reload the gun. But theres another problem that is it will reset the ammo to 0, so it will always reload the amount of maxammo you have even tho you still have bullets. For example, you have 7 ammo but the gun reloads 8 times still

function Reload()
	if not reloading and script.Parent.StoredAmmo.Value > 0 then
		reloading = true

		script.Parent.Ammo.Value = 0
		wait(0.1)

		while script.Parent.Ammo.Value < script.Parent.MaxAmmo.Value and script.Parent.StoredAmmo.Value > 0 do
			ShellInsert()
			script.Parent.Ammo.Value += 1
			script.Parent.StoredAmmo.Value -= 1
			wait(0.1)
		end

		reloading = false
	end
end

Nvm, I just thought of copying and looking at another fixed old gun (to be specific, Manofthelol’s) that just happened to be semi automatic and had manual reloading.

The function would look like this

function Reload()
	if script.Parent.Ammo.Value < script.Parent.MaxAmmo.Value and reloading == false and script.Parent.StoredAmmo.Value >= 1 then
		reloading = true
		for i = 1,script.Parent.MaxAmmo.Value - script.Parent.Ammo.Value do
			if canclereloading == true then
				canclereloading = false
				break
			end
			-- ...
			ShellInsert()
			if script.Parent.StoredAmmo.Value >= 1 then
				script.Parent.Ammo.Value = script.Parent.Ammo.Value + 1
				script.Parent.StoredAmmo.Value = script.Parent.StoredAmmo.Value - 1
			end -- this is getting annoying, and its not even half way done (thats from the original creator probably)
			task.wait(.1)
		end
		reloading = false
	end
end

Thanks for the help tho :+1: