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

Music Player does not play music?

Asked by 7 years ago

I made a part that when you touch it, music is supposed to start playing. The script is not local and the output says nothing. Help?

local debounce = true
script.Parent.Touched:connect(function(hit)
    if hit and hit.Parent:FindFirstChild('Humanoid') and debounce then
        debounce = false
        local player = game.Players:GetPlayerFromCharacter(hit.parent)
        local musicplaying = player:WaitForChild('PlayerScripts', 0.1):FindFirstChild('MusicPlaying')
        if musicplaying.Value == false then
            local randommusic = math.random(1,3)
            if randommusic == 1 then
                game.Workspace.music.lobbymusic.lobbymusic:Play()
                musicplaying = true
            elseif randommusic == 2 then
                game.Workspace.music.lobbymusic.lobbymusic2:Play()
                musicplaying = true
            elseif randommusic == 3 then
                game.Workspace.music.lobbymusic.lobbymusic3:Play()
                musicplaying = true
            end
        end
    end
end)

1 answer

Log in to vote
0
Answered by 7 years ago

Put this script inside of the brick. Try this:

local debounce = false

script.Parent.Touched:connect(function(hit)
if not debounce then 
    debounce = true 
    local check = hit.Parent:FindFirstChild("Humanoid")
    if check ~= nil then 
        local PlayerName = game.Players:GetPlayerFromCharacter(hit.Parent) 
         local MusicPlaying = PlayerName:WaitForChild('PlayerScripts', 0.1):FindFirstChild('MusicPlaying')
        if MusicPlaying == false then 
        local Ran = math.random(1,3)
        if Ran  == 1 then
            game.Workspace.music.lobbymusic.lobbymusic:Play()
            MusicPlaying = true
        elseif Ran == 2 then
            game.Workspace.music.lobbymusic.lobbymusi2:Play()
            MusicPlaying = true
        elseif Ran == 3 then
            game.Workspace.music.lobbymusic.lobbymusic3:Play()
            MusicPlaying = true
            end
            wait(3)
            end
        end
        end
    debounce = false
end)


0
all it does is delete the parent. output says nothing still. Lukeisbossman64 73 — 7y
Ad

Answer this question