Changing a value in a table does not work for some UNHOLY reason

I have a ModuleScript that’s supposed to hold settings and other stuff, but it’s mostly for settings. The problem is with the :ChangeSetting() function, it always says that there’s no setting with any name I put inside the arguments of it, even though a setting by that name DOES exist.

Here’s the ModuleScript:

local module = {}

local _settings = {
	["Hitboxes"] = false;
	["Headlock"] = false;
}

function _s:ChangeSetting(SettingName, NewValue)
	if table.find(_settings, SettingName) or _settings[SettingName] then
		_settings[SettingName] = NewValue
		print(_settings[SettingName])
	else
		return warn("'"..SettingName.."'".." is not a valid setting")
	end
end

function _s:GetSettings()
	return _settings
end

return module

Help a brotha out…
9166f3cb10934a7b36b8f56094a92f18

1 Like

Two problems with this line:

  1. table.find doesn’t work with dictionaries, only arrays.
  2. This checks if the value of the key in the _settings table is a truthy value, not if it exists

The check should look like this:

if _settings[SettingName] ~= nil then
2 Likes

Thanks! it actually works now!

Swagalicious…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.