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

[ SOLVED? ] How do I access Variables from another script?

Asked by 4 years ago
Edited 4 years ago

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 
05while true do
06 
07local table = {
08    s1,
09    s2,
10    s3,
11    s4,
12    s5 -- the table of the sounds
13}
14 
15local Randomizer = math.random(1,#table) -- the function that randomizes the items in the table
View all 26 lines...

LOCAL SCRIPT:

1--------------------------------------------------------
2-- SONG NAME
3--------------------------------------------------------
4 
5if music.IsPlaying then
6    name = Randomed.SOUND_NAME -- me trying to use the variable from the other script
7end

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.

0
You can make use of a "RemoteEvent" if you want to send information to a local script. Player1_Joined 271 — 4y
0
I'm not really good at scripting and I don't know how a RemoteEvent works but I'll try! OreoCakelover 17 — 4y
0
the main thing you want. is FireAllClients MrCatDoggo 213 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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 
05local GetSound = game.Workspace.Music_Playlist_v1.Sounds
06local Sound = Instance.new("Sound") -- creates a new sound to play
07local name = Instance.new("StringValue")
08 
09---------------------------------------------------------
10-- SONGS
11---------------------------------------------------------
12 
13local s1 = GetSound.Song1
14local s2 = GetSound.Song2
15local s3 = GetSound.Song3
View all 62 lines...

Local Script:

01---------------------------------------------------------
02-- VARIABLES
03---------------------------------------------------------
04 
05local MP = script.Parent
06local progress_bar = MP.PROGRESS_bar
07local progress = MP.PROGRESS_bar.progress
08local pause = MP.PAUSE_BUTTON
09local volume = MP.VOLUME_BUTTON
10local playing = MP.PLAYING_SONG
11local name = MP.PLAYING_SONG.SONG_NAME
12local music = game.Workspace.MusicPlayer
13local name2 = music.SOUND_NAME
14local test = Instance.new("Sound")
15 
View all 59 lines...

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.

Ad

Answer this question