Hello,
I have been working on my NPC framework and making sure it can run multiple groups. However, I have stumbled across a problem that I really don’t know the cause of. All the groups have the same name as the last group.
Sources
Image:
Handler script:
local rs = game:GetService("RunService")
local plrs = game:GetService("Players")
local group = require(script.group)
local model = game.ServerStorage.thing
local level = 1
local newcf = CFrame.new
local rand = Random.new()
local number_of_zombs = {
["Level 1"] = 4;
}
local zomb_groups = {}
local function on_char(c)
local num = number_of_zombs["Level "..level]
-- when more groups; make recursive function
for i = 1, num do
local start = workspace.spawns[i].Position
zomb_groups[i] = group.new(c.HumanoidRootPart, i, start)
print(zomb_groups[i])
end
wait(6)
for i, group in pairs(zomb_groups) do
print(i, group, group.name)
-- group:update(group.begin)
end
end
local function on_plrs(p)
p.CharacterAdded:Connect(on_char)
end
plrs.PlayerAdded:Connect(on_plrs)
OOP Group Script (didn’t put the whole thing because everything else was commented out so it couldn’t have been another method)
-- variables -----------------------------------------------------------------------------------------------------------
local PS = game:GetService("PathfindingService")
local RS = game:GetService("RunService")
local RE = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")
local USEFUL = require(script.useful_stuffs)
local FORMAT = string.format
local RAND = Random.new()
local NEWCF = CFrame.new
local YIELD = wait
local FLOOR = math.floor
local HIP = Vector3.new(0, 3, 0)
local MAX_DIST = 15
local WAIT_TIME = 0.6
local PATH_NAME = "path debug parts"
local DEBUG_WAYS = "old waypoints: % 2.0f | new waypoints: % 2.0f"
local SHOW_DEBUG = true
local create = RE.create
local info = RE.info
local moved = RE.move
local AGENT = {
["AgentRadius"] = 3;
["AgentHeight"] = 5;
["AgentCanJump"] = false;
}
local DEFAULT = {
path = game:GetService("PathfindingService"):CreatePath(AGENT);
zombs = {};
}
local npc = {
basic = SS.thing
}
-- class methods -------------------------------------------------------------------------------------------------------
local group = {}
group.__index = group
function group.new(obj, group_number, start)
local new = DEFAULT
new.target = obj
new.name = "group #"..group_number
new.begin = start
print(new.name, group_number)
local clone = npc.basic:Clone()
clone.Parent = game.ReplicatedStorage
create:FireAllClients(1, clone, group_number, new.name, new.begin)
return setmetatable(new, group)
end
Other notes:
- during the wait(6) in the handler script is where the name somehow changes
- on client, the names are still the same
If you some how find a solution or have questions, please let me know (note that I will be gone for 20 hours so don’t expect fast replies).
Anyways, thank you for your time!