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

how do i make an intro song that players only for the player that enters my game?

Asked by 9 years ago

i need help. i have a song that i want to play for the intro to my game but i cant make it play. plus when it does work it playes for everyone on the sever i need an intro song that will play for the person who joins the game when they join. HELP MEEEEEEE

0
playes my bad. my spelling and grammar sucks. bitner28663 0 — 9y
0
Would it kill you to attempt it? groovydino 2 — 9y

1 answer

Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
9 years ago

First of all, you need to understand the way that Roblox plays Sound. What it doesn't seem to talk about on the wiki however is how to play music for just a single player. This can be done quite easily actually, you just need to use a localscript.

"LocalScripts differ from regular Scripts as they do not run server-side, but instead, perform their actions on the client." (client is the person playing)

You want a person to join your game, and have it play the intro song, but only have that one person hear it? Use a localscript.

To have it only happen once (when they join) you can do this a few ways.

The first way, is to clone a localscript/Gui into the PlayerGui when they join. Example:

--This would go in a Script inside of ServerScriptService
game:GetService('Players').PlayerAdded:connect(function(player) --Whenever a player joins, run the following function
    script.LocalScript:Clone().Parent=player.PlayerGui --script.LocalScript (or whatever you decide) is cloned over to the player's PlayerGui
end)

The second, and better way, would be to create a value that does not go away when the player respawns, that we can check each time to make sure they already saw the intro

if script.Parent.Parent:FindFirstChild("DidWeSeeIntro")~=nil and script.Parent.Parent.DidWeSeeIntro.Value==true then --If DidWeSeeIntro object exists, and the value is true, run the intro code. Otherwise, don't.

--intro code here

--intro code here
end
local DidWeSeeIntro=Instance.new("BoolValue",script.Parent.Parent) --create a bool (true or false) value to say if we saw intro. Make sure that the script.Parent... part refers to the Player. PlayerGui's parent is Player. 
DidWeSeeIntro.Value=true --Set the Value to true, since we just went through the intro

For information on how to make sounds play using scripts, see here.

Edit: You actually don't need to check the value if it is true or not. You just check if your script already created one. That would look like this:

if script.Parent.Parent:FindFirstChild("DidWeSeeIntro")~=nil then --If DidWeSeeIntro object exists, run the intro code. Otherwise, don't.

--intro code here

--intro code here
end
local DidWeSeeIntro=Instance.new("BoolValue",script.Parent.Parent) --Make sure that the script.Parent... part refers to the Player. PlayerGui's parent is Player. We are creating an object that we can check locally each time this script starts (when they respawn).
Ad

Answer this question