Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Touched is not a valid member of Script? Tagged Plugin

Asked by
pilotly 14
10 days ago

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
0
well "tp" obviously has to be a script , so why is there a touched event created for "tp"? Tizzel40 225 — 10d

1 answer

Log in to vote
0
Answered by 8 days ago

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.

Ad

Answer this question