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

How to make part appear/disappear if a 'sound' is played by any player?

Asked by 6 years ago
Edited 6 years ago

``Hello there! I have no scripting skills, but I have tried my best, however it will not work. I have a part in the workspace named 'Part'. I am trying to make that part appear when any player is playing music '142376088'. When the player stops playing it, the part will disappear. Could I get some help? Thanks! It could be for the command :music 142376088, however I would prefer it be even on the players personal radio.

Edit: I actually want the part to be moved when the sound is detected, and moved back to its original position when the sound is off

[P.S I am a beginner scripter, only know the basic terms.. excuse my scripting below]

--I have no idea how to make it detect the sound
if game.Player.Types(":music 142376088")
    then
game.Workspace.Part.Position(-6, 336.5, -11) --I want this to be where is moved if the music is detected
 if game."Sound".Off --I want this to be if the sound is turned off
    then
    game.Workspace.Part.Position(23727, 336.5, -11) --I want this to be where is moved if music is turned off

Edit #2: With components that chess mentioned. I will change the name 'Part' to 'SpecialPart'. -I also want to use the command :music 142376088. So when it plays, the part is in position and when it is stopped, the part goes back

if musicId == 142376088 then
workspace.SpecialPart.CFrame = CFrame.new(-6, 336.5, -11) --Placement when :music 142376088 command is activated
sound.Stopped:Connect(function() --when music command is detected off
workspace.SpecialPart.CFrame = CFrame.new(23727, 336.5, -11) --Placement when :music 142376088 command is off
0
You need to post your code so that people can help you out. Axceed_Xlr 380 — 6y
0
how do you turn play/stop that sound? Ismax23 0 — 6y
0
Edit with my script. Please help me fix it BADABOO2016 3 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Ways of detecting the sound:

  • However the player asks for that music to be played, some script must act on their request. Find this bit and you can just add your instructions, like if musicId == 142376088 then workspace.SpecialPart.Visible = true end. You'll also need to connect Sound.Stopped to making it invisible: sound.Stopped:Connect(function() workspace.SpecialPart.Visible = false end) (of course, musicId and sound both need to exit / you need to replace that with whatever variable is already in use by the script.)
  • The Sound object is probably inserted into the workspace? Where-ever it is, you could listen for it (with ChildAdded), then check to see if it's a sound with the ID you want - this option is otherwise the same as the first.

Note: You specified you want workspace.Part to be modified, but in scripting you need to give these things unique names. Unless you have 0 other things named "Part" in the workspace, Roblox/Lua won't know which one you mean and will just choose the first one it finds.

Note 2; I specified workspace.SpecialPart.Visible = true, but it would also make sense to change the CanCollide to true/false. Alternatively, your Position idea would also work; here's the syntax: workspace.SpecialPart.CFrame = CFrame.new(-6, 336.5, -11) (You can also use Position, but it isn't guaranteed to go to the exact Position you want if there's already Parts there.)

0
I haved edited my question with (Edit #2), with your components. Please check if it is accurate, and what I need to fix. Thanks, chess! BADABOO2016 3 — 6y
0
You're missing an "end)" on line 5 (no quotes), and those lines have to be inserted in whatever script handles the music command / radio / whatever. Putting it right before "sound:Play()" or "music:Play()" or whatever it has will *probably* work. You may need to replace "musicId" with "music.SoundId" or "sound.SoundId" or whatever the variable is that has the ":Play()" command on it. chess123mate 5873 — 6y
Ad

Answer this question