Currently I want this dummy npc to constantly attack for testing purposes, but I don’t have a system in place to detect what weapon the dummy is using. I want it to use the default weapon which for me is Fists. However, since I check for weapons using the attribute stored in players I run into a error.
I know I’ll be using actual hostile NPCs later on so I want to ask where I store this information at sooner.
Here’s the code applied to every player (Unfinished):
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local Attributes = require(ServerStorage.Modules.GameModules.Attributes)
local Player = Players:GetPlayerFromCharacter(script.Parent)
local Character = script.Parent
local Weapon = Player:GetAttribute("Weapon")
Character.Parent = workspace.Entities.Alive
Character.HumanoidRootPart.CFrame = workspace.SpawnLocation.CFrame
Attributes:AddToCharacter(Character)
Player:SetAttribute("Weapon", "Fists")
Character:GetAttributeChangedSignal("Action"):Connect(function()
local CurrentAction = Character:GetAttribute("Action")
-- unfinished --
end)
Here’s a example of the code used to detect attacks
local Players = game:GetService("Players")
local WeaponSettings = require(ServerStorage.Modules.CombatModules.WeaponSettings) -- This is the weapon data stuff
local Lights = {}
function Lights:Start(Character : Instance)
local Player = Players:GetPlayerFromCharacter(Character)
local Humanoid = Character.Humanoid
local Weapon = Player:GetAttribute("Weapon") -- This is how I get the weapon
-- Rest of the code.
end
return Lights
As you can see from the script, it’s not possible to check any NPC for their weapon since the way I do it is through the player, not the character. I could attach the attribute to the character but the weapon attribute isn’t a constantly changing stat so I don’t want to try that solution just yet.
Should I make a big table storing the information of all the NPCs or maybe Every NPC and Player? I’m not really sure what to do.