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: Brick that plays audio when you step into it?

Previous Thread :: Next Thread 
Plasticine is not online. Plasticine
Joined: 30 Aug 2010
Total Posts: 2403
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
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
23 Jul 2015 07:44 AM
Check my libraries/models.
Report Abuse
fret13103 is not online. 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 is not online. 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
Plasticine is not online. Plasticine
Joined: 30 Aug 2010
Total Posts: 2403
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 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
23 Jul 2015 07:59 AM
dear lord
Report Abuse
fret13103 is not online. 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 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
23 Jul 2015 08:02 AM
(cringe)
Report Abuse
Rocketerkid is not online. Rocketerkid
Joined: 10 Oct 2011
Total Posts: 1237
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 is not online. 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
Rocketerkid is not online. Rocketerkid
Joined: 10 Oct 2011
Total Posts: 1237
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 is not online. 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 is not online. 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
Rocketerkid is not online. Rocketerkid
Joined: 10 Oct 2011
Total Posts: 1237
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 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
23 Jul 2015 08:12 AM
Yay someone noticed
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