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

why does this script dont give the prevate song to a player?

Asked by 7 years ago

Hello scripters, I'm making a game and theres a song, when a player joins the music starts (if its a new server) and if player one is already 30 sec in the game and a other player joins the music is already 30 seconds far, but I need that player one is still 30 sec and the new player that it begins for him and contunues for player one. what did I do wrong (the song is 108 seconds long) and one thing every 108 seconds later the song got to replay (for the player for who's song is done)

wait (5)
local sound = game.Workspace.LobbySound
local sound:play()
wait (108)
repeat

I hope you can help me, thanks, bye!

-Gamer_io

1
'prevate' AdvancedCode 136 — 7y

2 answers

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago

You need to play the sound locally inside the player upon joining :)

Use a PlayerAdded event, and wait for the Character to load. Then clone the sound into their PlayerGui, and play it.

local sound = workspace.LobbySound; --This is the sound
sound.Looped = true; --Make sure it loops

game.Players.PlayerAdded:Connect(function(plr) --PlayerAdded event
    local plrUI = plr:WaitForChild("PlayerGui"); --Get their PlayerGui
    plr.CharacterAdded:Wait(); --Wait for them to spawn
    local s = sound:Clone(); --Clone the sound
    s.Parent = plrUI; --Parent it to their PlayerGui
    s:Play(); --Play the cloned sound
end)
0
Thank you Goulstem, It helped me a lot :D Gamer_io 14 — 7y
Ad
Log in to vote
1
Answered by
Moxeh 84
7 years ago

Do this in a LocalScript. If this is a regular script, you are playing the same sound to every player. Store the sound within StarterPlayer so everyone starts with their own copy.

As far as the sound looping, if you only need it to play upon entering, I would just destroy the script and sound after waiting.

wait(108)
sound:Destroy()
script:Destroy()

Answer this question