#how do i improve my garbage code

1 messages · Page 1 of 1 (latest)

frosty mica
#

how do i improve my code ts so garbage

local funnySoundFolder = script.Parent:FindFirstChild("Funny Sounds")
local funnySounds = fFolder:GetChildren()
local fs1 = fFolder:FindFirstChild("1")
local fs2 = fFolder:FindFirstChild("2")
local fs3 = fFolder:FindFirstChild("3")
local fs4 = fFolder:FindFirstChild("4")

local function playfunnysound()
    local randomSound = funnySounds[math.random(1,4)]
    if randomSound == fs1 then
        if not (fs2.Playing == true or fs3.Playing == true or fs4.Playing == true) and fs1.Playing == false then
            fs1.PlaybackSpeed = math.random(70, 120) / 100
            fs1:Play()
        end
    elseif randomSound == fs2 then
        if not (fs1.Playing == true or fs3.Playing == true or fs4.Playing == true) and fs2.Playing == false then
            fs2.PlaybackSpeed = math.random(70, 120) / 100
            fs2:Play()
        end
    elseif randomSound == fs3 then
        if not (fs2.Playing == true or fs1.Playing == true or fs4.Playing == true) and fs3.Playing == false then
            fs3.PlaybackSpeed = math.random(70, 120) / 100
            fs3:Play()
        end
    elseif randomSound == fs4 then
        if not (fs2.Playing == true or fs3.Playing == true or fs1.Playing == true) and fs4.Playing == false then
            fs4.PlaybackSpeed = math.random(70, 120) / 100
            fs4:Play()
        end
    end
end
balmy cobalt
#
local funnySoundFolder = script.Parent:FindFirstChild("Funny Sounds")
local funnySounds = fFolder:GetChildren()
local fs1 = fFolder:FindFirstChild("1")
local fs2 = fFolder:FindFirstChild("2")
local fs3 = fFolder:FindFirstChild("3")
local fs4 = fFolder:FindFirstChild("4")

local function playfunnysound()
    local randomSound = funnySounds[math.random(1,4)]
if not (fs2.Playing == true or fs1.Playing == true or fs4.Playing == true) and fs3.Playing == false then
     randomSound.PlaybackSpeed = math.random(70, 120) / 100
     randomSound:Play()
end
end
#

something like this

stiff yoke
frosty mica
#
local funnySoundFolder = script.Parent:FindFirstChild("Funny Sounds")
local funnySounds = fFolder:GetChildren()
local fs1 = fFolder:FindFirstChild("1")
local fs2 = fFolder:FindFirstChild("2")
local fs3 = fFolder:FindFirstChild("3")
local fs4 = fFolder:FindFirstChild("4")

local function playfunnysound()
    local randomSound = funnySounds[math.random(1,4)]
if fs1.Playing == false and fs2.Playing == false and fs3.Playing == false and fs4.Playing == false then
     randomSound.PlaybackSpeed = math.random(70, 120) / 100
     randomSound:Play()
end
end
#

thanks man