Touched is not a valid member of Configuration with "CollectionService"

I’ve made 2 Kill Bricks inside of workspace where the Kill Bricks are stored in a Folder. Both Kills Bricks are united as a Part, however I found a issue regarding that the Touched event isn’t parent to the Tagged Object. The output tab displays this Error > 20:59:26.029 Touched is not a valid member of Configuration "ServerStorage.TagList.hi" - Server - KillBrick (CollectionService):28

(Please don’t judge I’m NEW to Lua scripting).

here is the code >

-- Services
local CollectionService = game:GetService("CollectionService")

-- Object
local KillBricks = workspace.KillBricks -- Parent of the Folder for the Kill Bricks

-- Settings
local ResetTime = 1 -- Time to Reset the funtion
local Debounce = false -- Added to prevent spam interference

-- Kill function
local function Kill(KillBrick) -- To contribute as a function
	local Player = KillBrick.Parent -- Detection of the Player
	local Humanoid = Player:FindFirstChild("Humanoid") -- Detection of the Player Humanoid
	if Debounce == false then -- Touched is (false)
		Debounce = true -- Touched is (true)
	if Humanoid then -- Detection if the Object is triggered by the Players Humanoid
			Humanoid.Health = 0 -- Player dies
			print("Touched the Kill Brick.") -- Inform if the Player has Touched the Kill Brick and Died
			task.wait(ResetTime) -- Reset mode
			Debounce = false -- Touched is (false) -- to prevent spam
		end
	end
end

-- Connect the Kill function
for _, KillBrick in pairs(CollectionService:GetTagged("hi")) do -- To contribute the Objects from the Folder
	print(KillBrick.ClassName)
   KillBrick.Touched:Connect(Kill) -- Firing the Touch function
end

The cause of the Error > KillBrick.Touched:Connect(Kill)

I’ve added print(KillBrick.ClassName) to detect the Class of the Kill Brick.

The output tab displays >

You have a Configuration object tagged with the "hi" tag, since it’s not a BasePart there is no Touched event for it.
Replace your for loop with this:

for _, KillBrick in pairs(CollectionService:GetTagged("hi")) do
    if KillBrick:IsA('BasePart') then
       print(KillBrick.ClassName)
       KillBrick.Touched:Connect(Kill) -- Firing the Touch function
    end
end
2 Likes

It worked thank you! However when the statement prints (Touched the Kill Brick." it prints 2x on Death. Any reason why this may occur?

I’ve rewritten your script to optimize it, make it a little bit easier on the eyes and also replaced CollectionService with just GetChildren() because if these kill bricks are already collected in to one folder in workspace then there is no need for CollectionService, but feel free to change it back if you want to.
I also added the for loop in to a standalone function and call the function using the task scheduler
The print('Touched the Kill Brick.') only prints once for me, note sure why it prints twice for you since there is already a debounce…

--// No need for CollectionService since the bricks are in the same folder, making tags useless, but if you really want you can use it

--// Constants
local KillBricks = workspace.KillBricks ::Folder -- Parent of the Folder for the Kill Bricks

--// Variables
local ResetTime = 1 -- Time to Reset the funtion
local Debounce = true -- Added to prevent spam interference

--// Functions
local function Kill(Part) -- To contribute as a function
  local Character = Part.Parent ::Model
  local Humanoid = Character:FindFirstChild('Humanoid') ::Humanoid
  if Humanoid and Debounce then
    Debounce = false
    Humanoid.Health = 0
    print('killed')
    task.wait(ResetTime)
    Debounce = true
  end
end

local function Connect()
  for _, KillBrick in ipairs(KillBricks:GetChildren()) do -- To contribute the Objects from the Folder
    KillBrick.Touched:Connect(Kill) -- Firing the Touch function
  end
end

-- Connections
task.spawn(Connect)

If you have any questions, please ask!

1 Like

I have already used GetChildren() I am still learning so I do simplify my scripts.

------------------------------------------------------------------------- Kill Brick (pairs with GetChildren())
-- Object
local KillBricks = workspace.KillBricks -- Parent of the Kill Brick Folder

-- Settings
local ResetTime = 1 -- Time to Reset the funtion
local Debounce = false -- Added to prevent spam interference

-- Kill function
local function Kill(KillBrick) -- To contribute as a function
	local Player = KillBrick.Parent -- Detection of the Player
	local Humanoid = Player:FindFirstChild("Humanoid") -- Detection of the Player Humanoid
	if Debounce == false then -- Touched is (false)
		Debounce = true -- Touched is (true)
	if Humanoid then -- Detection if the Object is triggered by the Players Humanoid
			Humanoid.Health = 0 -- Player dies
			print("Touched the Kill Brick.") -- Inform if the Player has Touched the Kill Brick and Died
			task.wait(ResetTime) -- Reset mode
			Debounce = false -- Touched is (false) -- to prevent spam
		end
	end
end

-- Connect the Kill function
for _, KillBrick in pairs(KillBricks:GetChildren()) do -- To contribute the Kill Bricks in the Folder
	KillBrick.Touched:Connect(Kill) -- Firing the Touch function
end
1 Like

what r u trying to make tho?

30char (ignore)

This topic has been closed so the issue is NO longer relevant.

1 Like