im trying to convert my npc stuff to collection service but for some odd reason it doesnt work again like the old code i used
Humanoid.Died:Connect(function()
local ChosenWeapon = RarityModule:GetRandomSlot(MobInfo.Weapons)
local ServerStorage = game.ServerStorage
local Items = ServerStorage.Items
local Weapon = Items[ChosenWeapon.Name]
-- cloned weapon
local ClonedWeapon = Weapon:Clone()
ClonedWeapon.Parent = workspace
ClonedWeapon.Handle.Position = NPCRootPart.Position
local Tag = CollectionService:GetTagged(MobInfo.MobZone)
local NPC = game.ServerStorage.NPC[MobInfo.MobZone][Humanoid.Parent.Name]
local MobFolder = workspace.MobHolder[MobInfo.MobZone]
-- loop through then set position then destroy
local Counter = 0
for _, Part in pairs(Tag) do
Counter = Counter + 1
local CounterPart = math.random(1, Counter)
NPC:Clone().Parent = MobFolder
NPC:MoveTo(Tag[Counter].Position, Tag[Counter])
-- destroy it
CollectionService:RemoveTag(NPCRootPart, Tag)
Humanoid.Parent:Destroy()
break
end
end)
The :GetTagged function requests for a Tag name, in string, can you make sure that you are passing a String? Also could you tell if there are any errors or stuff?
I don’t think there would be any specifics changes because all you probably changed was getting parts tagged as “StartingZone” with CollectionService & then looping through them and doing the same function?
I would say you to check till where the code is actually running, and it might be that you haven’t tagged the parts as StartingZone?
Actually it still works in the same way I believe, because you will obviously Destroy the Dead NPC & Create a new one. So you still need to bind it again, if you aren’t doing already.
I can see that your old code didn’t have the Remove Tag part, could you try removing it and then try?
Also, we don’t really know what most Variable values are and stuff, its pretty hard for us to debug your code without that, atleast for me it is, so you just need some patience to find the solution
-- // Services \\ --
local CollectionService = game:GetService("CollectionService")
local NPCRootParts = CollectionService:GetTagged("NPCRootParts")
local ServerStorage = game:GetService("ServerStorage")
-- Debounce
local DAMAGE_DEBOUNCE = false
local Connection = nil
local MobDone = false
-- loop through if touched then damage them
for _, NPCRootPart in pairs(NPCRootParts) do
if NPCRootPart:IsA("Part") then
-- // Parental Objects \\ --
local Humanoid = NPCRootPart.Parent.Humanoid
-- // Modules
local RarityModule = require(game.ReplicatedStorage.Shared.RarityModule)
local MobInfo = require(Humanoid.Parent.MobInfo)
-- // Events
Connection = Humanoid.Died:Connect(function()
local ChosenWeapon = RarityModule:GetRandomSlot(MobInfo.Weapons)
local ServerStorage = game.ServerStorage
local Items = ServerStorage.Items
local Weapon = Items[ChosenWeapon.Name]
-- cloned weapon
local ClonedWeapon = Weapon:Clone()
ClonedWeapon.Parent = workspace
ClonedWeapon.Handle.Position = NPCRootPart.Position
local Tag = CollectionService:GetTagged(MobInfo.MobZone)
local NPC = game.ServerStorage.NPC[MobInfo.MobZone][Humanoid.Parent.Name]
local MobFolder = workspace.MobHolder[MobInfo.MobZone]
-- loop through then set position then destroy
local Counter = 0
for _, Part in pairs(Tag) do
Counter = Counter + 1
local CounterPart = math.random(1, Counter)
NPC:Clone().Parent = MobFolder
NPC:MoveTo(Tag[Counter].Position, Tag[Counter])
-- destroy it
pcall(function()
Connection:Disconnect()
Connection = nil
MobDone = true
end)
CollectionService:RemoveTag(NPCRootPart, Tag)
Humanoid.Parent:Destroy()
break
end
end)
end
if MobDone then
break
end
end