#My Function eating out part of the code

3 messages · Page 1 of 1 (latest)

hardy trench
#
local function PianoTerra(sound)
  if sound then
    sound:Play()
  end
  -rest of the code-
end
PianoTerra(sound) --// with 
PianoTerra() --// without

could always add a parameter to the function and add a conditional check
if you want it to play a sound pass the soundID into the function
if not then it'll just continue as usual

#

also if you put all the children with ClickDetector under one folder you can just use one chunk of code for everything instead of making a line for each instance

local Folder = game.Workspace["Folder"]
for _,v in Folder:GetChildren() do
  v.ClickDetector.MouseClick:Connect(PianoTerra)
  end)
end
#
local Folder = game.Workspace["Folder"]
for _,v in Folder:GetChildren() do
  v.ClickDetector.MouseClick:Connect(function()
    if v:FindFirstChild("Sound") then --// replace "Sound" with sound name
      PianoTerra(v:FindFirstChild("Sound").ID) --// not sure what the ID property is named under sound instance
    else
      PianoTerra()
    end  
  end)
end

by putting everything under a folder and adding a sound under each of the parts you want to play a sound when clicked you can also just do this