I've been trying to reference my module script to 10 models instead add or modify the code lines in 10 models, just once with my module script?? I've been seeking for info on google, nothing really great resourceful to correct my mistakes
I know this is repetitive, perhaps I am beginner scripter as well.
local module = {} for _,v in pairs(folder:GetChildren()) do local model = v local pos = model.PositionColor local job = model.TitleColor local jobrank = model.RankColor EITHER OR --[[local pos = game.Workspace.FirstLevelSet.PositionColor local job = game.Workspace.FirstLevelSet.PositionColor local jobrank = game.Workspace.FirstLevelSet.TitleColor]]-- pos.Changed:connect(function() -- Worker if pos.Value == "Worker" then job.Transparency = 0 job.BrickColor = BrickColor.new("Institutional white") jobrank.Transparency = 1 elseif pos.Value == "SeniorWorker" then jobrank.BrickColor = BrickColor.new("Pink") jobrank.Transparency = 0 elseif pos.Value == "SupervisoryWorker" then jobrank.BrickColor = BrickColor.new("Really red") jobrank.Transparency = 0 elseif pos.Value == "ExecutiveWorker" then jobrank.BrickColor = BrickColor.new("Really black") jobrank.Transparency = 0 elseif pos.Value == "" then job.Transparency = 1 jobrank.Transparency = 1 end end) pos.Changed:connect(function() -- Janitor if pos.Value == "Janitor" then job.Transparency = 0 job.BrickColor = BrickColor.new("Medium blue") jobrank.Transparency = 1 elseif pos.Value == "SeniorJanitor" then jobrank.BrickColor = BrickColor.new("Reddish brown") jobrank.Transparency = 0 elseif pos.Value == "SupervisoryJanitor" then jobrank.BrickColor = BrickColor.new("Really black") jobrank.Transparency = 0 elseif pos.Value == "ExecutiveJanitor" then jobrank.BrickColor = BrickColor.new("Hot pink") jobrank.Transparency = 0 elseif pos.Value == "" then job.Transparency = 1 jobrank.Transparency = 1 end end) pos.Changed:connect(function() --IT Tech if pos.Value == "ITTech" then job.Transparency = 0 job.BrickColor = BrickColor.new("Hot pink") jobrank.Transparency = 1 elseif pos.Value == "SeniorITTech" then jobrank.BrickColor = BrickColor.new("Lime green") jobrank.Transparency = 0 elseif pos.Value == "SupervisoryITTech" then jobrank.BrickColor = BrickColor.new("Really black") jobrank.Transparency = 0 elseif pos.Value == "ExecutiveITTech" then jobrank.BrickColor = BrickColor.new("Institutional white") jobrank.Transparency = 0 elseif pos.Value == "" then job.Transparency = 1 jobrank.Transparency = 1 end end) pos.Changed:connect(function() --Supervisor if pos.Value == "Supervisor" then job.Transparency = 0 job.BrickColor = BrickColor.new("Really black") jobrank.Transparency = 1 elseif pos.Value == "LeadSupervisor" then jobrank.BrickColor = BrickColor.new("Dirt brown") jobrank.Transparency = 0 elseif pos.Value == "SeniorSupervisor" then jobrank.BrickColor = BrickColor.new("Deep orange") jobrank.Transparency = 0 elseif pos.Value == "ExecutiveSupervisor" then jobrank.BrickColor = BrickColor.new("Institutional white") jobrank.Transparency = 0 elseif pos.Value == "" then job.Transparency = 1 jobrank.Transparency = 1 end end) pos.Changed:connect(function() --Researcher if pos.Value == "Researcher" then job.Transparency = 0 job.BrickColor = BrickColor.new("Really red") jobrank.Transparency = 1 elseif pos.Value == "LeadResearcher" then jobrank.BrickColor = BrickColor.new("Fossil") jobrank.Transparency = 0 elseif pos.Value == "SeniorResearcher" then jobrank.BrickColor = BrickColor.new("Deep orange") jobrank.Transparency = 0 elseif pos.Value == "ExpertResearcher" then jobrank.BrickColor = BrickColor.new("Really black") jobrank.Transparency = 0 elseif pos.Value == "" then job.Transparency = 1 jobrank.Transparency = 1 end end) pos.Changed:connect(function() --Accountant if pos.Value == "Accountant" then job.Transparency = 0 job.BrickColor = BrickColor.new("New Yeller") jobrank.Transparency = 1 elseif pos.Value == "SeniorAccountant" then jobrank.BrickColor = BrickColor.new("Institutional white") jobrank.Transparency = 0 elseif pos.Value == "SupervisoryAccountant" then jobrank.BrickColor = BrickColor.new("Really black") jobrank.Transparency = 0 elseif pos.Value == "ExecutiveAccountant" then jobrank.BrickColor = BrickColor.new("Really red") jobrank.Transparency = 0 elseif pos.Value == "" then job.Transparency = 1 jobrank.Transparency = 1 end end) pos.Changed:connect(function() --Human Resource if pos.Value == "HumanResource" then job.Transparency = 0 job.BrickColor = BrickColor.new("Lime green") jobrank.Transparency = 1 elseif pos.Value == "SeniorHumanResource" then jobrank.BrickColor = BrickColor.new("Institutional white") jobrank.Transparency = 0 elseif pos.Value == "DirectorHumanResource" then jobrank.BrickColor = BrickColor.new("Really black") jobrank.Transparency = 0 elseif pos.Value == "ExecutiveDirectorHumanResource" then jobrank.BrickColor = BrickColor.new("Really red") jobrank.Transparency = 0 elseif pos.Value == "" then job.Transparency = 1 jobrank.Transparency = 1 end end) return module
If you are trying to shorten you're code, use dictionaries. I put an example below.
--Find Level and gold by StringRank RankDict = { ['Peasant'] = {1, 50}, ['Artisan'] = {2, 100}, ['Lord'] = {3, 250}, ['Shogun'] = {4, 500}, ['Monarch'] = {5, 1000} } local strRank = 'Peasant' local Level = RankDict[strRank][1] local gold = RankDict[strRank][2]
Hope this helps!