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)