I’ll refer to the two invisible parts as such…
The Block that turns on the audio ontouch = AudioBrick
The Block that turns off the audio ontouch = StopBrick
So right I’m trying to create an invisible brick that triggers that audio on touch. Now I’ve got the script working, fine and dandy for it to trigger the audio ontouch though I’m having a few problems with wanting to stop it after a player reaches a certain point outside the audio (To make the audio stop for when they touch a separate brick.)
The main issue I’m having is the script “stopping” the audio after a player reaches the “StopBrick”. Now the script does its the purpose of stopping the audio but when a player goes back to the “AudioBrick” it won’t play again, so it permanently breaks after touching the “StopBrick”
I’ve tried creating a few different combinations with Stop() and IsPlaying = True but nothing seems to work. I did try printing but it didn’t say much so I’m stuck on finding a way to stop the audio without breaking the “AudioBrick”
AudioBrick Script (Works fine)
local players = game:GetService("Players")
local part = script.Parent
local sound = part:WaitForChild("RinnieRat")
local debounce = false
local function onTouched(hit)
if debounce then
return
end
local hitModel = hit:FindFirstAncestorOfClass("Model")
if hitModel then
local hitPlayer = players:GetPlayerFromCharacter(hitModel)
if hitPlayer then
debounce = true
sound:Play(8810696186)
sound.Ended:Wait(30)
debounce = false
end
end
end
part.Touched:Connect(onTouched)
StopBrick Script (The Issue)
local players = game:GetService("Players")
local part = script.Parent
local sound = workspace.RinnieRatAudio.RinnieRat
local debounce = false
local function onTouched(hit)
if debounce then
return
end
local hitModel = hit:FindFirstAncestorOfClass("Model")
if hitModel then
local hitPlayer = players:GetPlayerFromCharacter(hitModel)
if hitPlayer then
debounce = true
sound:Stop(8810696186)
debounce = false
end
end
end
part.Touched:Connect(onTouched)