Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Touched is not a valid member of Script? Tagged Plugin

Hello, I come here once again for the help! I'm currently learning how to use the tagged plugin and I come across the error " Touched is not a valid member of Script". I know it has something to do with the tagged plugin and i am requesting the help of a more experienced developer! Thank you!

Code in question:

local CollectionService = game:GetService("CollectionService")
local teleport = CollectionService:GetTagged("Tel")
local tele1 = game.Workspace.telePads.telePad1
local tele2 = game.Workspace.telePads.telePad2
local db = true


for _, tp in pairs(teleport)do
	
	tp.Touched:Connect(function(hit)

Full Code:



local CollectionService = game:GetService("CollectionService")
local teleport = CollectionService:GetTagged("Tel")
local tele1 = game.Workspace.telePads.telePad1
local tele2 = game.Workspace.telePads.telePad2
local db = true


for _, tp in pairs(teleport)do
	
	tp.Touched:Connect(function(hit)
		
		local char = hit.Parent
		local hum = char:FindFirstChild("Humanoid")
		
		if hum and db then
			
			if tp.Name == "telePad1" then
				db = false
				-- send player to tele2
				char.HumanoidRootPart.CFrame = tele2.CFrame + Vector3.new(0,5,0)
				wait(3)
				db = true
			else
				if tp.Name == "telePad2" then
					db = false
					-- send player to tele1
					char.HumanoidRootPart.CFrame = tele1.CFrame + Vector3.new(0,5,0)
					wait(3)
					db = true
				end
			end
		end
		
	end)
end

1 comment

0

well "tp" obviously has to be a script , so why is there a touched event created for "tp"?

1 answer

do an Instance:IsA() check to make sure that "tp" is a BasePart

-- lines 8-10
for _, tp in pairs(teleport)do
	if (tp:IsA('BasePart')) then
		tp.Touched:Connect(function(hit)
			-- code here
		end);
	end
end

short explanation: the BasePart object refers to any type of physical part (MeshPart, Part, TrussPart, Union). by checking Instance:IsA('BasePart') you are essentially checking to make sure it is a part and you can use the Touched event on it.

This discussion is preserved as it was. New answers, comments, and votes are closed.