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 camera?

Hello, I am trying to make a semi-simple sound group script, to where when a player hits a certain brick, then sound starts to play.

In this script you will also see things for a gui moving in to tell them they have entered the town, just ignore that stuff.

Here is the script...

local TestTown = 130872377
local Wilderness = 138141118

local Sound = script.Parent
local replicatedStorage = game:GetService("ReplicatedStorage")
local remote = replicatedStorage:WaitForChild("Remote")

for i,v in pairs(game.Workspace:GetChildren("TestTownRegion")) do
	v.Touched:connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			local playerGui = game.Players[hit.Parent.Name]:WaitForChild("PlayerGui")
			local gameGui = playerGui:WaitForChild("DeadAhead")
			local values = playerGui:WaitForChild("Values")
			local navAspect = gameGui:WaitForChild("Navigation")
			local welcome = navAspect:WaitForChild("Welcome")
			local townName = welcome:WaitForChild("Town")
			
			local getTown = remote:WaitForChild("GetCurrentTown")
			local currentTown = getTown:InvokeServer()
			
			print("Copied Over Town!")
			
			local currentPlayerTown = values:WaitForChild("CurrentTown")
			
			Sound.SoundId = "rbxassetid://"..TestTown
			Sound.Volume = 1
			Sound:Play()
			
			townName.Text = currentPlayerTown.Value
			welcome:TweenPosition(UDim2.new(0.5, -125, 0.8, 0), "In", "Quint", 1.5)
			wait(2)
			welcome:TweenPosition(UDim2.new(0.5, -125, -1, 0), "Out", "Quint", 1.5)
		end
	end)
	v.TouchEnded:connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			Sound.SoundId = "rbxassetid://"..Wilderness
			Sound.Volume = 1
			Sound:Play()
		end
	end)
end

And I get the error: "Touched is not a valid member of camera | Line 9" however I NEVER had the camera defined anywhere. Any help?

1 answer

Your a bit confused here. **GetChildren()**doesn't accept args.**game.Wrkspace:GetChildren("TestTownRegion")**will simply return all the children of workspace. This is also where the "Camera" is located. Camera is a camera, and doesn't have a parts event. I'm sure this is the issue. You need to add something like:

if v.ClassName == "Part" then
	-- continue script
end

So only parts are listened to for the touched event.

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