I’m trying to learn collection service. I have a bunch of parts in my workspace with the tag “trap,” and when I run the game, I get this issue, any ideas why?
Touched is not a valid member of ServerScriptService "ServerScriptService"
code:
-- (all of this is in serverscriptservice, except for the parts)
local CollectionService = game:GetService("CollectionService")
local TaggedTraps = CollectionService:GetTagged("Trap")
for _, TaggedItem in pairs(TaggedTraps) do
TaggedItem.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
print(hit.Name)
end
end)
end
Are you tagging ServerScriptService
1 Like
You might be tagging Server script service also do this:
local CollectionService = game:GetService("CollectionService")
local TaggedTraps = CollectionService:GetTagged("Trap")
for _, TaggedItem in pairs(TaggedTraps) do
TaggedItem.Touched:Connect(function(hit)
if v:IsA("BasePart") then
if hit.Parent:FindFirstChild("Humanoid") then
print(hit.Name)
end
end
end)
end
1 Like
It’s probably because ServerScriptService is tagged with "Trap"
for some reason. If you can’t prevent it from doing that, try this:
local CollectionService = game:GetService("CollectionService")
local TaggedTraps = CollectionService:GetTagged("Trap")
for _, TaggedItem in pairs(TaggedTraps) do
if TaggedItem:IsA("BasePart") then
TaggedItem.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
print(hit.Name)
end
end)
end
end
1 Like