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

How do you make it so when you touch a block,it plays music?

Asked by 7 years ago

i don't know if this is about roblox lua though

1 answer

Log in to vote
1
Answered by
AmWrath 41
7 years ago

Well you have to use the Touched event and then use a method to make the sound play. Looks like low level research was gone into this one before asking but whatever.

local Sound = script.Parent:WaitForChild('Sound') -- Assuming sound is a child of your part and this script is also a child of the part
local Part = script.Parent

local SoundPlaying = false -- This is a boolean because we don't want the sound to play over and over every time we touch
Part.Touched:connect(function()
    if not SoundPlaying then
        SoundPlaying = true
        Sound:Play()
    end
end)

Sound.Ended:connect(function() -- This is to make it so when the sound ends we can touch the part again to make it play
    SoundPlaying = false
end)
0
cool Arthurama69 2 — 7y
Ad

Answer this question