#code error

6 messages · Page 1 of 1 (latest)

quasi sphinx
#

):

#

i was follow toturial but i had a problem if someone can fix it
handler ```lua
local SoundService = game:GetService("SoundService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local BackgroundMusic = SoundService:WaitForChild("BackgroundMusic")
local Settings = require(ReplicatedStorage:WaitForChild("Config"):WaitForChild("Settings"))

local module = {}

local function GetSettingByID(id: string)
for _, settingTable in pairs(Settings) do
if settingTable.ID then
return settingTable
end
end
end

function module.Music()
local info = GetSettingByID("Music")
print(info.Enabled)
if info.Enabled then
BackgroundMusic:Play()
else
BackgroundMusic:Pause()
end
end

BackgroundMusic:Play()

return module

module 
```lua

local module = {
    {ID = "Popup_Effects", Description    = "Disable the pupup effects for coins and food", Enabled = true},
    {ID = "Music", Description    = "22222222", Enabled = false},
    {ID = "SFX", Description    = "33333333", Enabled = true},
    {ID = "Trade_Request", Description    = "44444444", Enabled = true},
}

return module

manger

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Handler = require(script.Parent.Handler)
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local Settings = require(ReplicatedStorage:WaitForChild("Config"):WaitForChild("Settings"))
local player = Players.LocalPlayer

local screenGui = script.Parent
local frame = screenGui.Frame
local container = frame.Container.Container

local exit = frame.ExitButton

local template = container.Template

local ON_COLOR = Color3.fromRGB(65, 198, 4)
local OFF_COLOR = Color3.fromRGB(255, 0, 0)

local function GenerateSettings(setting: table)
    local clone = template:Clone()
    clone.Parent = container 
    clone.Name = setting.ID
    clone.Title.Text = setting.ID:gsub("_", " ")
    clone.Description.Text = setting.Description
    clone.Button.BackgroundColor3 = if setting.Enabled then ON_COLOR else OFF_COLOR
    clone.Button.Text = if setting.Enabled then "On" else "Off"
    clone.Visible = true    
    
    clone.Button.MouseButton1Click:Connect(function()
        setting.Enabled = not setting.Enabled
        clone.Button.BackgroundColor3 = if setting.Enabled then ON_COLOR else OFF_COLOR
        clone.Button.Text = if setting.Enabled then "On" else "Off"
        Handler[setting.ID]()
    end)
end

for _, settingTable in pairs(Settings) do
    GenerateSettings(settingTable)
end

exit.MouseButton1Click:Connect(function()
    screenGui.Enabled = false
end)
#

it was an tutorial

atomic eagle
#
type SettingData = {
    ID: string,
    Description: string,
    Enabled: boolean,
}
local function GetSettingByID(id: string): SettingData?
    for _, settingData in Settings do
        if settingData.ID == id then
            return settingData 
        end
    end

    return nil
end

You did not compare the setting's ID with the requested ID

#

You should change

function module.Music()
    local info = GetSettingByID("Music")
    print(info.Enabled)
    if info.Enabled then
        BackgroundMusic:Play()
    else
        BackgroundMusic:Pause()
    end
end


BackgroundMusic:Play()

return module

To

function module.Music()
    local info = GetSettingByID("Music")
    print(info.Enabled)
    if info.Enabled then
        BackgroundMusic:Play()
    else
        BackgroundMusic:Pause()
    end
end


module.Music()

return module

To properly initialize the setting