Try this
addEvent("onSettingChange", true)
addEventHandler("onSettingChange", localPlayer,
function(variable, value)
if variable == "draw_distance" then
local state = not (value == "Off")
draw.setVisible(state, true)
end
end)
function draw.setVisible(visible, notifyDisplay)
draw.visible = visible and true or false
draw.changeDistance(draw.visible)
if notifyDisplay then
triggerEvent("notification:create", localPlayer, "Draw distance", "is now "..(draw.visible and "ON" or "OFF"))
end
end
function draw.changeDistance(max)
for i,object in pairs(getElementsByType("object")) do
if isElement(object) then
local elementID = getElementModel(object)
engineSetModelLODDistance(elementID, max and 325 or 100)
end
end
end
function initialize()
draw.setVisible(true, false)
end
addEventHandler("onClientResourceStart", resourceRoot, initialize)
Your code had all sorts of logic errors, especially with the onClientResourceStart, which was only being added when you ran draw.setVisible, but also being attached for all resources, instead of just the current one. It would never run for the current resource that way.