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
currencyStore:Increment(-price)
local AmmoBox = game.Workspace.GlockAmmo
local Enabled = true
local Ammo = math.huge
local GunToRefillAmmo = {
"Glock",
}
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
GunScript.ChangeMagAndAmmo:FireClient(Player,Module.AmmoPerMag,ChangedAmmo,0)
end
end
end
end
end
end
end)