Hello I made a Basic TV and I need help with making the Images and Sounds script
so i made a button that plays a song and shows a image, a button to stop the song and take off the image, a button to pause it and resume it, and a button to volume up and down.
in the script i made the volume up button to change the volume to 3 if you click it and volume down to go to 0.5 if you click it and i also wanna play multiple songs and images if you keep pressing the buttons like random songs and images i put in a folder i dont know how to make the volume to contine going up or down instead of a certain number i dont know to make it put more images and sounds randomly or anything, What basic do I have to learn, or How do I achieve this
In order to make your Volume Up and Volume Down buttons work, try creating a variable that holds the current sound value and have the two volume buttons simply take a certain increment away from it, like this:
Make sure your TV contains two objects: an Image object to change every time we choose a new image and a sound object to change every time we choose a new sound
local SoundValue = 2 --Default sound value
local Increment = 0.25 --Change this to whatever you want, this determines how much the sound changes on every click
VolumeUpButton.ClickDetector.MouseClick:Connect(function()
if SoundValue < 3 then --Change this to the max sound you want
SoundValue += Increment --This is equal to SoundValue = SoundValue + Increment
TV.Sound.Sound = SoundValue --Sets the current audio's sound to this
end
end)
VolumeDownButton.ClickDetector.MouseClick:Connect(function()
if SoundValue > 0 then --Change this to the min sound you want
SoundValue += -Increment --This is equal to SoundValue = SoundValue - Increment
TV.Sound.Sound = SoundValue --Sets the current audio's sound to this
end
end)
As for random images and sounds, use a while loop that operates as long as the TV is on. Possibly like this:
local TVIsOn = false --Make this change in the Power On/Off button event
local Sounds = SoundsFolder:GetChildren() --Folder with all audios
local Images = ImagesFolder:GetChildren() --Folder with all images
PowerOnButton.ClickDetector.MouseClick:Connect(function()
TVIsOn = true
while TVIsOn do
TV.Image.Image = "rbxassetid://"..Images[math.random(1,#Images)].Image --Chooses a random image
TV.Sound = "rbxassetid://"..Sounds[math.random(1,#Images)].SoundId --Chooses a random sound
wait(math.random(1,10) --Change this to a max value you want an image to appear for
end
end)
PowerOffButton.ClickDetector.MouseClick:Connect(function()
TVIsOn = false --Stops the loop above
end)
This might be very confusing if you’re new to scripting, so I recommend you read about variables, functions and loops to understand the above. I haven’t tested this so it may not even work, and you have to set the right directories for the aforementioned TV.Image, TV.Sound. SoundsFolder and ImagesFolder.