Need help fixing my gun ammo purchase script!

I am trying to create a system to buy ammo. The buying part works correctly, however the ammo part is not working. It does not go to the gun.

local DataStore2 = require(1936396537)
local replicatedStorage = game:GetService("ReplicatedStorage")
local defaultCurrencyAmount = 100
local price = 30


replicatedStorage.RemoteEvents.GlockAmmo.OnServerEvent:Connect(function(player, itemName)
	local currencyStore = DataStore2("currency", player)
	print "Sup"
		if currencyStore:Get(defaultCurrencyAmount) >= price then
		local AmmoBox = game.Workspace.GlockAmmo
		local Enabled = true
		local Ammo = math.huge 
		local GunToRefillAmmo = {

		local players = game:GetService("Players")
		local Player = players.LocalPlayer
			if Enabled and Player then
				local AmmoRefilled = false
				for _, GunName in pairs(GunToRefillAmmo) do
					local Gun = Player.Backpack:FindFirstChild(GunName) or Player.Character:FindFirstChild(GunName)
					if Gun then
						local GunScript = Gun:FindFirstChild("GunScript_Server")
						local Module = Gun:FindFirstChild("Setting")
						if GunScript and Module then
							local Module = require(Module)
							if GunScript.Ammo.Value < Module.MaxAmmo and Module.LimitedAmmoEnabled then

								AmmoRefilled = true
								local ChangedAmmo = (Ammo == math.huge or GunScript.Ammo.Value + Ammo >= Module.Ammo) and Module.MaxAmmo or (GunScript.Ammo.Value + Ammo)
								GunScript.Ammo.Value = ChangedAmmo


One thing I’m noticing is that you’re indexing the LocalPlayer, but the server can’t do that obviously. LocalPlayer only updates for each individual player (locally) so the server will always see that pointing to nil.

With that said, you don’t even need to use the LocalPlayer, as when Remote Events are fired the player who fired the remote is passed through the function parameters, so you can use your player parameter instead. Might be the issue here.

I replaced

local players = game:GetService("Players")
		local Player = players.LocalPlayer


local function Enabler(Player)

Still no luck