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

How Can I make A LocalScript activate only once while it is in the starterGUI?

Asked by 7 years ago

Hello,

I have just made a music playlist.... which is just a folder in the Workspace full of sounds (all unique and numbered) And, I also have a Localscript in the StarterGUI that makes it when a player joins the game.... one of the songs from the playlist plays.... then it waits for the song to finish... then the next song plays after that....

This script was made with very little effort as it was very simple and without any complications...When I went to test it in the game.... the script worked, and sounds were playing 1 by 1 from the playlist....But when I got another player to join....the local script started playing another song for the player that had just joined....So basically, There were 2 sounds playing at once......

Ok, So I partially know what happened....Since the script was in StarterGUI, it automatically had a player entered function...Which caused the script to be working on both of the players making 2 Sounds play at once.

So, now I am trying to think of a way to figure out how to have the local script work once when the first player is joined... and then when a second player has joined... it wont start the script up again...So what I'm trying to do is only have 1 script working at one time......

If anyone could help me do this or has another Idea of how I can overcome this problem, please Write an answer or in a comment!

Thanks, King

1 answer

Log in to vote
0
Answered by 7 years ago

You say that "Since the script was in StarterGUI, it automatically had a player entered function". The solution, then, is simple -- remove the event connection to the "player entered function". ex.

game.Players.PlayerAdded:connect(function(player)
    --main function content here
end)

--Convert the above to:

function RunMusic()
    local player = game.Players.LocalPlayer
    --main function content here
end
RunMusic()
Ad

Answer this question