I need help with CollectionServer

Hello!

This is my AoE damage (didn’t work)

for _, Target in pairs(CollectionService:GetTagged("PlrHumanoids")) do
	if Target:IsA("Model") and Target:FindFirstChild("Humanoid") and Target.Parent.Name ~= Character.Name then --Checking if we have a valid model
		connection2:Disconnect()
		local Humanoid = Target
		local RootPart = Target.HumanoidRootPart
		if (RootPart.Position - LightBombClone.Position).Magnitude < Radius then --Checking if there are Targets in range of the AOE
			connection2:Disconnect()
			Humanoid:TakeDamage(Damage)
		end
	end
end

and this is my way to catch all players’ humanoids, why it didn’t work?

in ServerScriptService:

local CollectionServer = game:GetService("CollectionService")

game.Players.PlayerAdded:Connect(function(Plr)
	local Hum = Plr:FindFirstChild("Humanoid")
	CollectionServer:AddTag(Hum, "PlrHumanoids")
	print(Hum)
	print(CollectionServer:GetTagged("PlrHumanoids"))
end)`

Why are you disconnecting your function twice? Couldn’t you just remove those?

lag reduction, if possible I would like you to focus on my question, I need help, i’ll fix it later

Could you print out what Target is before you start your conditional checks?

do you know how to use magnitude?

You’re using Magnitude right, the issue is that either the GetTagged function returned back by the loop isn’t finding anything, or you’re not referencing a variable correctly

Actually looking at it again, you’re referencing Target as the Humanoid, and this line here would result in an error:

Change that to

local RootPart = Target.Parent.HumanoidRootPart

It didn’t work, i think this will help you…

local CollectionServer = game:GetService("CollectionService")

game.Players.PlayerAdded:Connect(function(Plr)
	local Hum = Plr:FindFirstChild("Humanoid")
	CollectionServer:AddTag(Hum, "PlrHumanoids")
	print(Hum)
	print(CollectionServer:GetTagged("PlrHumanoids"))
end)

image

Player objects don’t have a Humanoid object inside them, you have to reference their Character first if you want to add them to the PlrHumanoids table

local CollectionServer = game:GetService("CollectionService")

game.Players.PlayerAdded:Connect(function(Plr)
    Plr.CharacterAdded:Connect(function(Character)
	    local Hum = Character:WaitForChild("Humanoid")
	    CollectionServer:AddTag(Hum, "PlrHumanoids")
	    print(Hum)
	    print(CollectionServer:GetTagged("PlrHumanoids"))
    end)
end)

Oh ty i am so dumb, didn’t work, output:

image

Ok wut how

Now I’m just confused, that should work though?

Try referencing the string as a global variable instead?

how? i don’t know how to use CollectionService

If you don’t even know how to use it, I’d recommend looking at this post: