I'm making a music playlist that can shuffle for a friend. I'm trying to figure out how to use a variable from another script, like global variables. I don't know how it works since I'm not that good at scripting. One of the scripts is local, the local script is the script I'm trying to use the variable from the other script. (* if that makes sense.* )
SCRIPT:
01 | --------------------------------------------------------- |
02 | -- MUSIC |
03 | --------------------------------------------------------- |
04 |
05 | while true do |
06 |
07 | local table = { |
08 | s 1 , |
09 | s 2 , |
10 | s 3 , |
11 | s 4 , |
12 | s 5 -- the table of the sounds |
13 | } |
14 |
15 | local Randomizer = math.random( 1 ,#table) -- the function that randomizes the items in the table |
LOCAL SCRIPT:
1 | -------------------------------------------------------- |
2 | -- SONG NAME |
3 | -------------------------------------------------------- |
4 |
5 | if music.IsPlaying then |
6 | name = Randomed.SOUND_NAME -- me trying to use the variable from the other script |
7 | end |
I found out an easier way to do it! Thank you for the help but I don't need any more help with this question.
Well, I solved the problem but I didn't use RemoteEvent or Global Variables, it looks like there was an easier way! Here's how I did it ( you don't have to read it all btw ):
Server Script:
01 | --------------------------------------------------------- |
02 | -- VARIABLES |
03 | --------------------------------------------------------- |
04 |
05 | local GetSound = game.Workspace.Music_Playlist_v 1. Sounds |
06 | local Sound = Instance.new( "Sound" ) -- creates a new sound to play |
07 | local name = Instance.new( "StringValue" ) |
08 |
09 | --------------------------------------------------------- |
10 | -- SONGS |
11 | --------------------------------------------------------- |
12 |
13 | local s 1 = GetSound.Song 1 |
14 | local s 2 = GetSound.Song 2 |
15 | local s 3 = GetSound.Song 3 |
Local Script:
01 | --------------------------------------------------------- |
02 | -- VARIABLES |
03 | --------------------------------------------------------- |
04 |
05 | local MP = script.Parent |
06 | local progress_bar = MP.PROGRESS_bar |
07 | local progress = MP.PROGRESS_bar.progress |
08 | local pause = MP.PAUSE_BUTTON |
09 | local volume = MP.VOLUME_BUTTON |
10 | local playing = MP.PLAYING_SONG |
11 | local name = MP.PLAYING_SONG.SONG_NAME |
12 | local music = game.Workspace.MusicPlayer |
13 | local name 2 = music.SOUND_NAME |
14 | local test = Instance.new( "Sound" ) |
15 |
If you didn't know, I'm making a music player that shuffles the music. I was having trouble creating the "song playing" script but eventually, I did it! Thanks for all the help though, I appreciate it.