Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can anyone help me on a script that relates to debounce,audio and function (hit)?

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)

2 comments

0

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)

0

whats you question?

1 answer

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

1 comment

0

i would just use...

This discussion is preserved as it was. New answers, comments, and votes are closed.