|
| 25 Feb 2016 02:20 PM |
Basically I'm trying to make a PA speaker system, that would randomly choose a song from a list of ids, and play them until they end, then it would choose a new song id and play that. I think I know how to do it all, but I would like to know how to just name all the speaker bricks the same, and make the script just act as if it was changing it for one brick, but then repeat it on every brick named "PASpeaker", until all of them are done.
cats cats cats |
|
|
| Report Abuse |
|
|
ElectroTM
|
  |
| Joined: 23 Nov 2012 |
| Total Posts: 1135 |
|
|
| 25 Feb 2016 02:22 PM |
why don't you just control them individually and name them something like "Speaker1" or something?
y-y-you too... |
|
|
| Report Abuse |
|
|
| |
|
|
| 25 Feb 2016 02:26 PM |
@ElectroTM I plan making the system very large, so naming every brick "Speaker1,Speaker2,...,Speaker 50" and then making an operation for every one isn't really what i'd consider "efficient".
cats cats cats |
|
|
| Report Abuse |
|
|
|
| 25 Feb 2016 02:27 PM |
@128 How would I do that? I'm not very experienced with loops, so I can't figure how to.
cats cats cats |
|
|
| Report Abuse |
|
|
|
| 25 Feb 2016 02:28 PM |
for _, child in next, (game.Workspace:getChildren()) do if (child:isA("BasePart")) then child.BrickColor = BrickColor.new("Bright red") end end |
|
|
| Report Abuse |
|
|
|
| 25 Feb 2016 02:50 PM |
So it would be something like this?
for _, child in next, (game.Workspace.SpeakerSet:getChildren()) do if (child:isA("BasePart")) and child.Name = "PASpeaker" then music = Instance.new("Sound") music.Parent = child music.SoundId = {random id chosen by script} music:Play() end end
cats cats cats |
|
|
| Report Abuse |
|
|
|
| 25 Feb 2016 02:54 PM |
' child.Name = "PASpeaker"'
Should be
child.Name == "PASpeaker" Also make sure to pick the random ID before the loop so they all have the same sound. |
|
|
| Report Abuse |
|
|
|
| 25 Feb 2016 02:54 PM |
I noticed that and fixed it. I'll post the full script when i'm done.
cats cats cats |
|
|
| Report Abuse |
|
|
|
| 25 Feb 2016 04:37 PM |
Here's the full script:
--PA System script by xFloweyTheFlower (kirbyofdeath) print("OMG IT'S STARTING")
music = {"198268150","178790549","366885056","142523674","294215823","330617313"} --our music list :D
for _, asset in ipairs(music) do --preload them because why not! game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=" .. asset) print("preloading omg") end
function SongEnded() local SelectedId = "rbxassetid://" ..music[math.random(#music)] --selecting a song w00t! print("Selected song ID: "..SelectedId)
for _, child in next, (game.Workspace.SpaceLab.Speakers:getChildren()) do if (child:isA("BasePart")) and child.Name == "PASpeaker" then music = child.Music music:Stop() print("Stopped song!") wait(5) music.SoundId = SelectedId music:Play() print("Started song woot!") end end end wait() --just to be safe
if script.StartedPlaying.Value ~= true then SongEnded() --checks if it's playing? script.StartedPlaying.Value = true --PLAY IT! end
--EVENTS OMG music.Ended:connect(SongEnded)
It gives me this error: 16:35:24.829 - Workspace.PASpeaker Script:12: attempt to get length of global 'music' (a userdata value) 16:35:24.829 - Stack Begin 16:35:24.830 - Script 'Workspace.PASpeaker Script', Line 12 16:35:24.830 - Stack End
why is it saying this?
cats cats cats |
|
|
| Report Abuse |
|
|
| |
|
|
| 26 Feb 2016 06:41 AM |
You used music as a bariable teice Once for a table and once for a music instance |
|
|
| Report Abuse |
|
|
|
| 26 Feb 2016 12:33 PM |
holy crap how did i make a mistake like that thanks it works now :D
cats cats cats |
|
|
| Report Abuse |
|
|
|
| 26 Feb 2016 03:17 PM |
odd in studio it works perfectly, but in online mode it doesn't change to the next song. it just stops with no error.
cats cats cats |
|
|
| Report Abuse |
|
|
|
| 26 Feb 2016 06:17 PM |
Put wait() right after you stop the sound, or right before you play it. And make sure you preload all your sounds. |
|
|
| Report Abuse |
|
|
|
| 27 Feb 2016 12:40 PM |
still doesn't work...
cats cats cats |
|
|
| Report Abuse |
|
|
|
| 27 Feb 2016 01:13 PM |
Wait for the players character to load.. Player:WaitForChild("Character") if this is a local script then just wait for the camera repeat wait() until game.CurrentCamera == true
#code if SxDev == legitness then print("Legitness UnMeasured") return legitness end |
|
|
| Report Abuse |
|
|
|
| 27 Feb 2016 01:15 PM |
??? How would waiting for the player affect the music?
Here's my current script:
--PA System script by xFloweyTheFlower (kirbyofdeath) print("OMG IT'S STARTING")
musiclist = {"198268150","178790549","366885056","294215823","330617313"} --our music list :D
for _, asset in ipairs(musiclist) do --preload them because why not! game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=" .. asset) print("preloading " .. asset .. " omg") end
function SongEnded() print("please work D:") local SelectedId = "rbxassetid://" ..musiclist[math.random(#musiclist)] --selecting a song w00t! print("Selected song ID: "..SelectedId)
for _, child in next, (game.Workspace.SpaceLab.Speakers:getChildren()) do if (child:isA("BasePart")) and child.Name == "PASpeaker" then music = child.Music music.SoundId = SelectedId wait() music:Play() print("Started song woot!") end end end wait() --just to be safe
if script.StartedPlaying.Value ~= true then SongEnded() --checks if it's playing? script.StartedPlaying.Value = true --PLAY IT! end
--EVENTS OMG music.Ended:connect(SongEnded)
cats cats cats |
|
|
| Report Abuse |
|
|
|
| 28 Feb 2016 03:23 AM |
1.You can not do player:waitForChild("Character") and expect it to do that. Because .Character is a property not a child. You can do this local character = (player.Character or player.characterAdded:wait())
2.game.Workspace.CurrentCamera is also a property and it will never equal "true" because its value is an instance. |
|
|
| Report Abuse |
|
|
|
| 28 Feb 2016 12:24 PM |
repeat wait() print("WAITING FOR BECOMING TRUE") until game.Workspace.CurrentCamera print("TRUE") -- This does become true eventually
#code if SxDev == legitness then print("Legitness UnMeasured") return legitness end |
|
|
| Report Abuse |
|
|
|
| 28 Feb 2016 01:24 PM |
No it does not become true it becomes non nil/false
repeat --[[Things]] until x
Will repeat until x is not nil and x is not false. game.Workspace.CurrentCamera will either be nil or a camera instance. |
|
|
| Report Abuse |
|
|
|
| 29 Feb 2016 10:31 AM |
I thought of an different way that might work. I'm hoping that instead of using Play(), that setting the sounds to loop and only changing the id will work.
cats cats cats |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 29 Feb 2016 10:34 AM |
for i,v in next, model:GetChildren() do if v:IsA("Sound") then v.soundID = "rbxassetid://32456754" v:Play() end end
|
|
|
| Report Abuse |
|
|