of     1   

Rex005X
#228134484Monday, November 27, 2017 4:15 AM GMT

I have been messing around with the .Touched() event, trying to make a "SoundZone" script that plays audio when the character touches an object. Unfortunately the custom character that I'm trying to use fires the .Touched() event multiple times therefore lagging the game intensely. Applying a debounce to prevent the audio from playing will not help. It's the .Touched() event combined with the custom character that is generating the lag.
Rex005X
#228134546Monday, November 27, 2017 4:17 AM GMT

Anyway my question is, is there a way to stop multiple .Touched() events from happening? All I need is just for the event to fire once, or atleast some form of slowing the freakin' thing down so it doesn't lag the game.
Scarious
#228134622Monday, November 27, 2017 4:19 AM GMT

Once one event fires, trigger a server event to disable the script for a given interval of time before enabling it again? While also having the server complete the task for said touched event*
Spectrum555
#228134682Monday, November 27, 2017 4:21 AM GMT

you can disconnect the event when they touch it... Players = game.Players local event event = part.Touched:connect(function(hit) if Players:GetPlayerFromCharacter(hit.Parent) then Sound:Play() event:Disconnect() end end)
nofascistsaloudxD
#228134727Monday, November 27, 2017 4:22 AM GMT

Do as I suggested previously, in your other forum... Simply make the script check the name of the part that has touched it. If the part's name is "HumanoidRootPart" then run the script. However, if the name is not, then don't do anything..
Quirtx
#228134739Monday, November 27, 2017 4:23 AM GMT

You could use a debounce in you script.
Rex005X
#228134981Monday, November 27, 2017 4:30 AM GMT

@nofascistsaloudxD I tried your suggestion and it did not work. Thanks anyway. Also I have tried a version of what the first person suggested and it works. I will try the disconnect suggestion too.
Rex005X
#228135431Monday, November 27, 2017 4:46 AM GMT

I managed to create two versions. Both of them work perfectly. Thank you all for your suggestions and I shall put them to good use. Have a good day or night! :)
Rex005X
#228135944Monday, November 27, 2017 5:03 AM GMT

I believe I have completed the script. I'll post it here because I believe all of you who helped me deserve to know how to make the same thing for your games. Enjoy! Model Structure Below... -Game --StarterGui ---ScreenGui <-- ScreenGui ---PartDetector <-- LocalScript ---Sound <-- Audio ---CopyName <-- LocalScript ---NVAL <-- StringValue Also a large part in Workspace that is transparent, anchored, and collisions turned off. ---PartDetector LocalScript--- local event local Aname = script.Parent.NVAL while true do wait(5) event = game.Workspace.Part.Touched:connect(function(t) if t.Parent.Name == Aname.Value then if script.Parent.Sound.IsPlaying == true then event:disconnect() end if t.Parent.Name == Aname.Value then if script.Parent.Sound.IsPlaying == false then script.Parent.Sound:Play() event:disconnect() end end end end) end ---CopyName LocalScript Below--- local P = script.Parent.Parent.Parent local V = script.Parent.NVAL V.Value = P.Name script:Destroy()

    of     1