Hi! I was wondering how I would reference audio from an array I set up. Basically, I want to be able to detect the brick (which should be named Road). Then, it detects if the player is in a seat, and if they are I want it to be able to find the Road color, then reference that sound, and play it. How would I reference that? Thanks for the help!
== Mike
`
-- Code --
Asphalt1Color = 163, 162, 165 Asphalt1Sound = "http://www.roblox.com/asset/?id=1962370858" Asphalt2Color = 91, 93, 105 Asphalt1Sound = "http://www.roblox.com/asset/?id=1962369936" ConcreteRoad1Color = 226, 220, 188 ConcreteRoad1Sound = "http://www.roblox.com/asset/?id=1962367857" ConcreteRoad2Color = 241, 231, 199 ConcreteRoad2Sound = "http://www.roblox.com/asset/?id=2156073955" ConcreteBridge1Color = 211, 190, 150 ConcreteBridge1Sound = "http://www.roblox.com/asset/?id=1962368939" ConcreteBridge2Color = 199, 172, 120 ConcreteBridge2Sound = "http://www.roblox.com/asset/?id=2156079001" ConcreteBridge3Color = 202, 191, 163 ConcreteBridge3Sound = "http://www.roblox.com/asset/?id=2156072943" local sounds = game.ServerStorage.RoadSounds local player = game.Player.Character or game.Player.CharacterAdded:Wait() for i, v in pairs (player:GetChildren()) do if v.IsA('BasePart') then if v.Name('Road') then v.Touched.Connect(function() --At this point, I'd like to ref the color and sound then play it end end) end end end end`
(there may be too many ends here too)
I tried editing the script. Put this inside StarterGui for it to work properly.
local RoadTable = { Color3.new(163, 162, 165), "1962370858", --Asphalt1 Color3.new(91, 93, 105) , "1962369936" --Asphalt2 } --Add more and add a note in-case you forgot which color plays which sound and what's the name of the sound and color is. local sound = Instance.new("Sound") sound.Volume = 0.7 --Change the volume here sound.Parent = script.Parent local player = game.Player.Character or game.Player.CharacterAdded:Wait() local BasePrefix = "rbxassetid://" --(This is faster than http://www.roblox.com/asset/?id=) local function PlaySound(part) for i=1,#RoadTable,2 do if part.Color = RoadTable[i] then sound.SoundId = BasePrefix..RoadTable[i+1] sound:Play() end end end for i, v in pairs (player:GetChildren()) do if v.IsA('BasePart') then if v.Name('Road') then v.Touched.Connect(function(part) PlaySound(part) end) end end end
If you want more sounds. Just