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

Playing Sound for one player?

Asked by 7 years ago

When game runs sound plays normally, but when you click button it doesn't stop

game.Players.PlayerAdded:connect(function(plr)


            local startsound = plr.PlayerGui:FindFirstChild('Sound')

            if startsound then
                if startsound.Name == "BackgroundMusic" then
                    startsound:Play()
                end
            end

        game.StarterGui.ScreenGui.StartFrame.PlayButton.MouseButton1Click:connect(function()
            local stopsound = plr.PlayerGui:FindFirstChild('Sound')

            if stopsound then
                if stopsound.Name == "BackgroundMusic" then
                    stopsound:Stop()
                end
            end
        end)
end)

1 answer

Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

You bind the click function to the StarterGui*. You should use the plr.PlayerGui instead.

*StarterGui is the service that clones all instance inside of it, to the players PlayerGui when their character gets added. (On entering the game, or respawning)

Ad

Answer this question