|
| 23 Jul 2015 07:41 AM |
| I simply need a scripted part that will play music when you walk into the area it's in. I'd just make it transparent and turn off CanCollide, I don't need to know how to script it as I literally just need to use it this one instance. So I'm wondering what I'd need to search for to find a model like this? Ty |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2015 07:44 AM |
| Check my libraries/models. |
|
|
| Report Abuse |
|
|
fret13103
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 881 |
|
|
| 23 Jul 2015 07:48 AM |
It's easy to make dis
get your audio you want put it into audio object in game and put that into brick and name it Audio
then put this code into brick
game:GetService("RenderService").RenderStepped:connect(function() if GetDistance(ClosestPlayer()) < 20 then script.Parent.Audio:Play() end end)
function GetDistance(pos1, pos2) local PosX = pos1.Position.x local PosZ = pos1.Position.z local PosX2 = pos2.Position.x local PosZ2 = pos2.Position.z local DistX = PosX - PosX2 local DistZ = PosZ - PosZ2 local DistanceX = DistX*DistX local DistanceZ = DistZ*DistZ local DistanceSq = DistanceX + DistanceZ local Distance = math.sqrt(DistanceSq) return Distance end
function ClosestPlayer() local closesttorso = nil for _, v in pairs(workspace:GetChildren()) do if v:isA("Model") and v:findFirstChild("Torso") and v ~= script.Parent.Parent then local Torso = v:findFirstChild("Torso") local VPosition = Torso.Position if closesttorso == nil then closesttorso = Torso elseif _G.GetDistance(VPosition, script.Parent) < _G.GetDistance(closesttorso, script.Parent) then closesttorso = Torso end end end return(closesttorso) end
make sure your baseplate doesnt go into negatives because it might glitch out the GetDistance function, and you'd have to write a better one for it to work; which I'm to lazy to do. It's a bit messy but it works for me when I tested in studio.
|
|
|
| Report Abuse |
|
|
fret13103
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 881 |
|
|
| 23 Jul 2015 07:49 AM |
| add Spawn(wait()) into the RenderStepped loop!! Or it wont work! |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2015 07:52 AM |
| I couldn't find what I needed in your inventory cody, but thanks fret, I will try that. Help appreciated :) |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
| |
|
fret13103
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 881 |
|
|
| 23 Jul 2015 08:00 AM |
| lol I didnt even use GetDistance right did I ... It's meant to be GetDistance(script.Parent, ClosestPlayer()) or smth. |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
| |
|
|
| 23 Jul 2015 08:03 AM |
game:GetService("RenderService").RenderStepped:connect(function()
What's RenderService? o3o...
Also, I think for RunService the code has to be a local script.
|
|
|
| Report Abuse |
|
|
fret13103
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 881 |
|
|
| 23 Jul 2015 08:04 AM |
riiight, I definitely meant to say RunService...
...
...
ok cringe time https://www.youtube.com/watch?v=lBICLteuQs8 |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2015 08:05 AM |
Yes, but even then putting the script inside the brick like you said wouldn't work wit RenderStepping. :( It has no client to use.
|
|
|
| Report Abuse |
|
|
fret13103
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 881 |
|
|
| 23 Jul 2015 08:07 AM |
yeah I defo meant local script...
...
I give up. |
|
|
| Report Abuse |
|
|
fret13103
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 881 |
|
|
| 23 Jul 2015 08:07 AM |
| I've never used RenderStepped, atleast I know this now, ^-^. |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2015 08:08 AM |
There's no real need for returning distance using a method like that.
Magnitude is a lot more efficient. |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
| |
|