(SOLVED) Script Isn't Creating TouchTransmitter

I am trying to write a script that plays an audio when you enter an area, and stops when you leave. The part for the area is called CityArea and the audio is called City. The part has collision off. I’m a complete beginner, so please be patient with me. When I run the script I get the error "Unable to create an Instance of type “TouchTransmitter”

I’ve tried googling for help, and everything is saying to manually insert the TouchTransmitter but I don’t understand what they mean by that. Once again, I am a complete beginner so please explain this to me like I don’t know what I’m doing (because I don’t.) Thanks!

Here’s my code:

local CityArea = game.Workspace:FindFirstChild("CityArea")
local touchTransmitter = Instance.new("TouchTransmitter")
touchTransmitter.Parent = CityArea
print("TouchTransmitter created successfully")

local sound = game.Workspace:FindFirstChild("City")
sound.Looped = true
sound.Volume = 0.5

function onTouch(part)
	if part.Parent:FindFirstChild("Humanoid") then
		sound:Play()
	end
end

function onLeave(part)
	if part.Parent:FindFirstChild("Humanoid") then
		sound:Stop()
	end
end

touchTransmitter.TouchStarted:Connect(onTouch)
touchTransmitter.TouchEnded:Connect(onLeave)

Ensure that CityArea is a BasePart (a part, union, etc), and replace FindFirstChild with WaitForChild incase your script loads before the object.

TouchTransmitters can only be children of BaseParts.

1 Like

Where you found that information?

Its not possible to create an Instance TouchTransmitter. Base parts that has CanTouch enabled are ready to trigger the event Touched and TouchEnded, not TouchedStarted

local CityArea = game.Workspace:WaitForChild("CityArea")

local sound = game.Workspace:WaitForChild("City")
sound.Looped = true
sound.Volume = 0.5

function onTouch(part)
	if part.Parent:FindFirstChild("Humanoid") then
		sound:Play()
	end
end

function onLeave(part)
	if part.Parent:FindFirstChild("Humanoid") then
		sound:Stop()
	end
end

CityArea.Touched:Connect(onTouch)
CityArea.TouchEnded:Connect(onLeave)
2 Likes

I was using ChatGPT to help (it’s AI so of course it isn’t completely accurate) and some person’s YouTube tutorial told me that lol, but I was able to fix it and it works now! Thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.