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
1 | hitm:Play() |
2 |
3 | wait(.) |
4 |
5 | debounce = false |
6 |
7 | end |
8 |
9 | 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:
01 | local mat = workspace.Part |
02 | local debounce = false |
03 | local sc = workspace.mat |
04 | local hitm = sc.music |
05 | mat.Parent.Touched:Connect( |
06 | function (hit) |
07 | if hit.Parent:FindFirstChild( "Humanoid" ) and debounce = = false then |
08 | debounce = true |
09 | hitm:Play() |
10 |
11 | wait() |
12 |
13 | hitm.Ended:Wait() |
14 | debounce = false |
15 | end |
16 | end |
17 | ) |
also, use hitm.Ended:Wait()
to wait until the audio ends