Zarteon
|
  |
| Joined: 25 Apr 2011 |
| Total Posts: 2085 |
|
|
| 02 Dec 2012 08:24 AM |
I'm working a new game and I'm trying to create some realism therefore I am wondering how I can create a script that plays a sound only when the player is like 8 studs from them etc.
Thanks, Much Appreciated. |
|
|
| Report Abuse |
|
|
Zarteon
|
  |
| Joined: 25 Apr 2011 |
| Total Posts: 2085 |
|
|
| 02 Dec 2012 08:40 AM |
Something like this...
local effect = script.Effect
while true do wait () p = game.Workspace:GetChildren() for i = 1,#p do local g = p[i]:findFirstChild("Torso") if (g==nil)then return end if (g.Position - script.Parent.Position).magnitude < 5 then hum:play() end end end
Isn't it? |
|
|
| Report Abuse |
|
|
Zarteon
|
  |
| Joined: 25 Apr 2011 |
| Total Posts: 2085 |
|
|
| 02 Dec 2012 08:41 AM |
local effect = script.Effect
while true do wait () p = game.Workspace:GetChildren() for i = 1,#p do local g = p[i]:findFirstChild("Torso") if (g==nil)then return end if (g.Position - script.Parent.Position).magnitude < 5 then effect:play() end end end
I took it from my Microphone coding, So would that work? |
|
|
| Report Abuse |
|
|
|
| 02 Dec 2012 08:44 AM |
You could do that or you could place the sound INSIDE of the part and play it from there so that the sound only plays near the part (Not the whole entire world)
And you could possibly lower the sounds volume so they can only hear it when they are close. |
|
|
| Report Abuse |
|
|
Zarteon
|
  |
| Joined: 25 Apr 2011 |
| Total Posts: 2085 |
|
|
| 02 Dec 2012 08:49 AM |
I've adapted the script to the following...
local effect = script.Parent.Effect
while true do wait () p = game.Workspace:GetChildren() for i = 1,#p do local g = p[i]:findFirstChild("Torso") if (g==nil)then return end if (g.Position - script.Parent.Position).magnitude < 5 then effect:play() end end end
But... It is not functioning, Any ideas what could be the problem... |
|
|
| Report Abuse |
|
|
|
| 02 Dec 2012 08:51 AM |
"wait ()"
That should be wait()
After that I don't see any other problem but other then the fact that I don't really like your coding style (Sorry for being such a hipster right there lol)
|
|
|
| Report Abuse |
|
|
Zarteon
|
  |
| Joined: 25 Apr 2011 |
| Total Posts: 2085 |
|
|
| 02 Dec 2012 08:53 AM |
| As long as it does the job. xD. |
|
|
| Report Abuse |
|
|
Zarteon
|
  |
| Joined: 25 Apr 2011 |
| Total Posts: 2085 |
|
|
| 02 Dec 2012 08:55 AM |
| Okay, I've changed that but it still doesn't appear to be functioning... |
|
|
| Report Abuse |
|
|
|
| 02 Dec 2012 09:00 AM |
If you want to check if a player's torso is near the part you could do each of the following:
local thingy = game:GetService("Players") for _,b in pairs(thingy:GetChildren()) do if (b.Position - script.Parent.Position).magnitude < 5 then --blah
And you might want to put this script in the player's character itself and run a check in it to check if it is near the part.
Sorry for any confusion this might cause.
You might also want to take this to scripting helpers next though. |
|
|
| Report Abuse |
|
|
Zarteon
|
  |
| Joined: 25 Apr 2011 |
| Total Posts: 2085 |
|
|
| 02 Dec 2012 09:02 AM |
Okay, I'll take it to scripting helpers. I mainly posted here originally to see what I basically needed to do.
|
|
|
| Report Abuse |
|
|
Zarteon
|
  |
| Joined: 25 Apr 2011 |
| Total Posts: 2085 |
|
|
| 02 Dec 2012 09:10 AM |
Just like to update you guys. I've managed to fix the script.
Thanks for your contributions. |
|
|
| Report Abuse |
|
|
|
| 02 Dec 2012 09:26 AM |
It's actually pretty simple; the sound should be based off the player's magnitude to the object.
That's what I did on my Soundscape place.
☜▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☞ |
|
|
| Report Abuse |
|
|
|
| 02 Dec 2012 09:49 AM |
You don't even need a script for this, fewls.
SoundService FTW. |
|
|
| Report Abuse |
|
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
|
| 02 Dec 2012 03:34 PM |
| Local sounds: in playergui |
|
|
| Report Abuse |
|
|
|
| 02 Dec 2012 11:35 PM |
@Prehistoric;
Yes; use both scripting and soundservice to create perfect sound.
Oh if ROBLOX made local soundservice and lighting I could make the perfect immersive game!!111!1!!
*ahem* Dynamic Light Adjust *ahem* Dynamic Mumbled Sounds *Ahem* Dynamic Brightness etc.
☜▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☞ |
|
|
| Report Abuse |
|
|