So basically I'm doing a simple thing where when I land my torso onto the part it will play the audio, which the audio is located in the part called "Mat" Not sure If I'm doing things in reverse but please help anyone
local mat = workspace.Part
local debounce = false
local sc = workspace.mat
local hitm = sc.music
mat.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid")and debounce == true then
hitm:Play() wait(.) debounce = false end end)
You made debounce = false, whcih is good, but the problem why it doesn't work is because you did and debounce == true
, but it's false, so it will never happen. so try this:
local mat = workspace.Part local debounce = false local sc = workspace.mat local hitm = sc.music mat.Parent.Touched:Connect( function(hit) if hit.Parent:FindFirstChild("Humanoid") and debounce == false then debounce = true hitm:Play() wait() hitm.Ended:Wait() debounce = false end end )
also, use hitm.Ended:Wait()
to wait until the audio ends