generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Sound Script Not Working

Previous Thread :: Next Thread 
imcool105 is not online. imcool105
Joined: 22 Feb 2011
Total Posts: 40
27 Mar 2015 10:28 PM
This script was supposed to make a button able to locally play sound, and when touched again (a different copy of the button) stop the previous, and play a new sound.


function onTouch(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
local Sound = Instance.New("Sound")
Sound.SoundID = "http://www.roblox.com/asset/?id=165000427"
Sound.Parent = game.Players.LocalPlayer.PlayerGUI
if (humanoid ~= nil) then -- if a humanoid exists, then
Sound: Play()
end
end

script.Parent.Touched:connect(onTouch)
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
27 Mar 2015 10:29 PM
First of all, does that play the sound at all?
Report Abuse
lunarvoidknight12 is not online. lunarvoidknight12
Joined: 09 Apr 2011
Total Posts: 214
27 Mar 2015 10:30 PM
Dunno if you got the right sound id, try creating a sound, placing just the numbers into it and then after hitting enter copy that into your script.
Report Abuse
imcool105 is not online. imcool105
Joined: 22 Feb 2011
Total Posts: 40
27 Mar 2015 10:35 PM
Considering I'm new to scripting I have no idea half of what I'm doing. Thats why I need a little help. :/
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
27 Mar 2015 10:36 PM
I'll be glad to help. First I need to know if the sound is playing. Is it?
Report Abuse
imcool105 is not online. imcool105
Joined: 22 Feb 2011
Total Posts: 40
27 Mar 2015 10:41 PM
It doesn't work at all, I put it in a part (in workspace) titled "SoundBrick" And inserted it into a localscript that was a child of that part.
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
27 Mar 2015 10:46 PM
I suppose you should try this.

local Sound = game.Players.LocalPlayers.PlayerGui.Sound

function onTouch(part)
Sound:Play()

end
end

script.Parent.Touched:connect(onTouch)

Put this in a local script, and make sure you have "Sound" put into PlayerGui. To do that, inside of the sound in a local script do

script.Parent.Parent = game.Players.LocalPlayer.PlayerGui
Report Abuse
imcool105 is not online. imcool105
Joined: 22 Feb 2011
Total Posts: 40
27 Mar 2015 10:52 PM
Still not working, I'm so puzzled.
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
27 Mar 2015 10:53 PM
Let me experiment in studio with this then.
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
27 Mar 2015 10:55 PM
Found the issue.
You can't use that way of doing it in a local script, because I guess the server handles the touched event. I'll try and see if there's another way.
Report Abuse
imcool105 is not online. imcool105
Joined: 22 Feb 2011
Total Posts: 40
27 Mar 2015 10:57 PM
I'm making a club game and just want the music to change from room to room. (Through touching bricks that are can collided false and transparent.) Didn't think it would be that hard. ;-;
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
27 Mar 2015 10:59 PM
Does it have to be local, because if not, this will be easier.
Report Abuse
imcool105 is not online. imcool105
Joined: 22 Feb 2011
Total Posts: 40
27 Mar 2015 11:03 PM
I'd like it to play for only one player. Not for all players. For example, if a player touched the button the song would only play for that player. And if another button was touched and stopped that song and played that buttons song, it would only be for that player.
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
27 Mar 2015 11:06 PM
I can see why you'd want that, but so far I haven't been able to get the touched event to work from a local script. Don't worry though, I'll try and get it to work.
Report Abuse
imcool105 is not online. imcool105
Joined: 22 Feb 2011
Total Posts: 40
27 Mar 2015 11:07 PM
Dude, you deserve a cookie.
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
27 Mar 2015 11:08 PM
Try this in a normal script inside of the part. It worked for me in Studio. And put the sound you want to play inside of StarterGui.

function onTouch(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if (humanoid ~= nil) then -- if a humanoid exists, then
local p = game.Players:FindFirstChild(part.Parent.Name)
if p ~=nil then
p.PlayerGui.Sound: Play()
end
end
end

script.Parent.Touched:connect(onTouch)
Report Abuse
imcool105 is not online. imcool105
Joined: 22 Feb 2011
Total Posts: 40
27 Mar 2015 11:13 PM
YES THANK YOU OH MAH GAWD
Report Abuse
imcool105 is not online. imcool105
Joined: 22 Feb 2011
Total Posts: 40
27 Mar 2015 11:14 PM
And to make multiple do I change "Sound" to Sound1 and name the sound object Sound1?
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
27 Mar 2015 11:17 PM
Yeah.
Report Abuse
imcool105 is not online. imcool105
Joined: 22 Feb 2011
Total Posts: 40
27 Mar 2015 11:19 PM
One problem. The sound doesn't stop when another is touched.
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
27 Mar 2015 11:22 PM
To do that just put this inside of the part you want to turn it off like you did the one to turn it on

function onTouch(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if (humanoid ~= nil) then -- if a humanoid exists, then
local p = game.Players:FindFirstChild(part.Parent.Name)
if p ~=nil then
p.PlayerGui.Sound: Stop()
end
end
end

script.Parent.Touched:connect(onTouch)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image