Hi!
Pretty simple problem, I can’t figure out why this value (self.equipped) is returning as nil. It shouldn’t be as far as I can tell.
This is the LocalScript which hands off self.equipped to the module:
local StarterPlayer = game:GetService("StarterPlayer")
local PlayerModule = StarterPlayer:WaitForChild("StarterPlayerScripts"):WaitForChild("PlayerModule")
local ControlModule = PlayerModule:WaitForChild("ControlModule")
local WeaponSystemClientside = require(ControlModule.WeaponSystemClientside)
local tool = script.Parent
local configuration = tool.Configuration
--// These are separate for organisation purposes \\--
local function handOffVariables()
WeaponSystemClientside.ammoCapacity = configuration.AmmoCapacity
WeaponSystemClientside.currentAmmo = configuration.CurrentAmmo
WeaponSystemClientside.magCapacity = configuration.MagCapacity
WeaponSystemClientside.currentMag = configuration.CurrentMag
WeaponSystemClientside.shotCooldown = configuration.ShotCooldown
end
-- This is to catch if something goes wrong when changing weapons for testing purposes
-- probably doesnt need to exist when script is finished. Idk
local function deleteVariables()
WeaponSystemClientside.ammoCapacity = nil
WeaponSystemClientside.currentAmmo = nil
WeaponSystemClientside.magCapacity = nil
WeaponSystemClientside.currentMag = nil
WeaponSystemClientside.shotCooldown = nil
end
-- This lets the server know whether the weapon is equipped or not
tool.Equipped:Connect(function()
WeaponSystemClientside.equipped = true
handOffVariables()
end)
tool.Unequipped:Connect(function()
WeaponSystemClientside.equipped = false
deleteVariables()
end)
This is the ModuleScript which should recieve the value. The :Update function is being renderstepped from a different module - this definitely works as intended, I’ve tested.
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local WeaponSystemLink = ReplicatedFirst:WaitForChild("WeaponSystemLink")
local WeaponSystemClientside = {}
WeaponSystemClientside.__index = WeaponSystemClientside
function WeaponSystemClientside.new()
local self = setmetatable({}, WeaponSystemClientside)
self.BaseWeapon = require(script:WaitForChild("BaseWeapon"))
self.Animation = require(script:WaitForChild("Animation"))
self.Effects = require(script:WaitForChild("Effects"))
self.passAction = WeaponSystemLink:WaitForChild("PassActions")
-- These are gained from ControlModule
self.isPrimaryFire = false
self.isSecondaryFire = false
self.isLastWeaponSwitch = false
-- These are gained from the weapon's configuration
self.ammoCapacity = nil
self.currentAmmo = nil
self.magCapacity = nil
self.currentMag = nil
self.shotCooldown = nil
-- This is gained from the weapon when equipped
self.equipped = false :: boolean
-- This is sent to the server so it knows when the gun can fire
self.enabled = false
return self
end
function WeaponSystemClientside:Update()
print(self.equipped)
end
return WeaponSystemClientside
A lot of the information in these scripts is probably not relevant but I wanted to make 100% sure anything that is important is included.
Any help would be appreciated, thanks.