Skip to content

Commit e9f63a2

Browse files
committed
No ammo fix
1 parent 0af9798 commit e9f63a2

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

Data/Scripts/WeaponSwitcher_Server.lua

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,39 @@ local function SetupNewWeapon(player, inventory, slot)
2121
return nil
2222
end
2323

24-
local weapon = World.SpawnAsset(inventory:GetItem(slot).itemTemplateId)
24+
local item = inventory:GetItem(slot)
25+
local weapon = World.SpawnAsset(item.itemTemplateId)
2526
weapon:Equip(player)
2627

27-
-- Connect the weapon events to update Ammo property
28-
if not weapon.isHitscan then
29-
weapon.projectileSpawnedEvent:Connect(UpdateWeaponAmmo)
30-
else
31-
local shootAbility = weapon:GetAbilities()[1]
32-
if shootAbility then
33-
shootAbility.executeEvent:Connect(function(ability)
28+
if item:GetCustomProperty("Ammo") then
29+
-- Connect the weapon events to update Ammo property
30+
if not weapon.isHitscan and weapon.projectileSpawnedEvent then
31+
weapon.projectileSpawnedEvent:Connect(UpdateWeaponAmmo)
32+
else
33+
local shootAbility = weapon:GetAbilities()[1]
34+
if shootAbility then
35+
shootAbility.executeEvent:Connect(function(ability)
36+
Task.Wait()
37+
UpdateWeaponAmmo(ability:FindAncestorByType('Weapon'))
38+
end)
39+
end
40+
end
41+
local reloadAbility = weapon:GetAbilities()[2]
42+
if reloadAbility then
43+
reloadAbility.executeEvent:Connect(function(ability)
3444
Task.Wait()
3545
UpdateWeaponAmmo(ability:FindAncestorByType('Weapon'))
3646
end)
37-
end
38-
end
39-
local reloadAbility = weapon:GetAbilities()[2]
40-
if reloadAbility then
41-
reloadAbility.executeEvent:Connect(function(ability)
42-
Task.Wait()
43-
UpdateWeaponAmmo(ability:FindAncestorByType('Weapon'))
44-
end)
45-
end
46-
47-
-- Setup ammo for current weapon
48-
if inventories[player].ammo then
49-
weapon.currentAmmo = inventory:GetItem(slot):GetCustomProperty("Ammo")
50-
else
51-
inventory:GetItem(slot):SetCustomProperty("Ammo", weapon.currentAmmo)
52-
inventories[player].ammo = true
53-
end
47+
end
48+
49+
-- Setup ammo for current weapon
50+
if inventories[player].ammo then
51+
weapon.currentAmmo = inventory:GetItem(slot):GetCustomProperty("Ammo")
52+
else
53+
inventory:GetItem(slot):SetCustomProperty("Ammo", weapon.currentAmmo)
54+
inventories[player].ammo = true
55+
end
56+
end
5457
return weapon
5558
end
5659

0 commit comments

Comments
 (0)