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

How do i make something play music on touch?

Asked by 10 years ago

function OnTouched(hit) script.Parent.WhatEverTheMusicIsNamed:Play() end wait (1) script.Parent.Touched:connect(onTouched)

1 answer

Log in to vote
0
Answered by 10 years ago

If you mean as in click, then do this. Get any object and put it in a model with a ClickDetector. Then put Sound and a Script inside the object. Name the Sound, "Music". Then put this inside the script.

local isOn = false

function on()
    isOn = true
    script.Parent.Music:Stop()
end

function off()
    isOn = false
    script.Parent.Music:Play()
end

function onClicked()

    if isOn == true then off() else on() end

end

script.Parent.Parent.ClickDetector.MouseClick:connect(onClicked)

on()

all good to go.

-- ur welcom
Ad

Answer this question