Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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)
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) JerkDerekThe14alt 11 — 3y
0
whats you question? Cats767_99 -68 — 3y

1 answer

Log in to vote
0
Answered by
raid6n 2196 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

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

0
i would just use... Cats767_99 -68 — 3y
Ad

Answer this question