Hello, fellow people! So, I was scripting my gun system (just started it) and I encountered a problem. There is a Boolean attribute inside of the gun (model) named IsReloading. And basically the script has a part where if it can’t find any of the given attributes (in a table) it throws out an error and returns nil. I do have the attribute inside of the gun, but it’s skipping it. When I make the IsReloading attribute any other, for example, string or number. It perfectly works. It might be a bug, but I’m not sure. I could use folders instead of attributes which isn’t a problem, but I want this problem to be spotted by developers.
Module Script:
--// Tables
local _Weapon = {}
--// Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--// ReplicatedStorage Variables
local Weapons = ReplicatedStorage:WaitForChild("Weapons")
--// Main functions
function _Weapon:InitializeWeapon(weapon : Model)
local AttributesRequired = {
[1] = "WeaponType"; -- Weapon type (Pistol, Automatic, Semi-Automatic, Shotgun, Sniper)
[2] = "Recoil"; -- Vector3 value
[3] = "MaxBullets"; -- Max bullets you can have at a time
[4] = "CurrentAmmoAmount"; -- Current ammo
[5] = "IsReloading"; -- Will be set to true if you're reloading the gun at the moment.
}
for i, v in pairs(AttributesRequired) do
if not weapon:GetAttribute(v) then
warn(string.format(("There isn't a(n) %s attribute in %s."), v, weapon.Name))
return nil
end
end
print("All perfect!")
end
--// Other
return _Weapon
Main script (that I used for testing):
local _Weapon = require(game.ReplicatedStorage.Modules:WaitForChild("_Weapon"))
_Weapon:InitializeWeapon(game.ReplicatedStorage.Weapons.Model)
A picture that shows the attributes:
Thank you for reading!