How to improve this code for a tutorial/story

i will this use in the story of my game too and then save atributes so the story contineu where you was there lso a part where in one function you can go to more prompts if you do function – mouseclick – mouseclick that should work right

local atribute = script.Parent

local HW = script.Parent.Parent.Parent.Parent.Parent["auto properties"].Assets.AutoProperties
local PF = script.Parent.Parent.Parent.Parent.Parent["auto properties"].Assets.properties

local main = HW:WaitForChild("main")
local PFmain = PF:WaitForChild("main")

local back = atribute.content.title.aback
local nextt = atribute.content.title.cnext

local close = atribute.content.title.zclose

local prompt = atribute
local title = atribute.content.title.btitle
local img = atribute.content.img
local text = atribute.content.text

local tabsmodule = require(main.aTabs.tabs)

local function stop() -- stop all tool tips
	main.aTabs.gui.Tooltip.Visible = false
	main.aTabs.gui.Tooltip.Active = false
	main.guis.aUidragdetector.title.tooltip.ToolTip.Visible = false -- change soon
	main.guis.aUidragdetector.title.tooltip.ToolTip.Active = false -- change soon
	PFmain.uidragdetector.scroller.badata.top.tooltip.ToolTip.Visible = false -- soon change
	PFmain.uidragdetector.scroller.badata.top.tooltip.ToolTip.Active = false -- soon change
	PFmain.uidragdetector.scroller.cbehaviorpropperties.properties.enabled.tooltip.ToolTip.Visible = false -- soon change
	PFmain.uidragdetector.scroller.cbehaviorpropperties.properties.enabled.tooltip.ToolTip.Active = false -- soon change
	PFmain.uidragdetector.top.tooltip.ToolTip.Visible = false -- soon change
	main.guis.ascrennui.tooltip.ToolTip.Visible = false -- soon change
	main.guis.aUidragdetector.title.tooltip2.ToolTip.Visible = false -- soon change
	main.aTabs.settings.Tooltip.Visible = false
	main.btopbar.content.aselectsettings.tooltip.ToolTip.Visible = false
	main.aTabs.more.Tooltip.Visible = false
	main.more.apps.grid.tooltip.ToolTip.Visible = false
	
end

local function navigation1()
	if atribute:GetAttribute("navigation") == true then
		tabsmodule.none()
		main.aTabs.gui.Tooltip.Visible = true
		main.aTabs.gui.Tooltip.Active = true

		main.aTabs.gui.Tooltip.MouseButton1Click:Connect(function() 
			stop()
			atribute:SetAttribute("navigation", false)
			atribute:SetAttribute("props1", true)
		end)
		
		nextt.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("navigation") == true then
			
			stop()
			atribute:SetAttribute("navigation", false)
				atribute:SetAttribute("props1", true)
			end
		end)
		
		back.Visible = false
		nextt.Visible = true
		prompt.Visible = true
		title = "navigation"
		img = ""
		text = "lets we as first navigate the plugin you see the topbar then click on gui to navigate to gui you also can navigate to other (3d stuff and more) apps (feedback and more) or settings (gearwheele)"
	end
end

local function props1()
	if atribute:GetAttribute("props1") == true then
		
		main.guis.aUidragdetector.title.tooltip.ToolTip.Visible = true -- soon change
		
		main.guis.aUidragdetector.title.aproperties.MouseButton1Click:Connect(function() -- soon change
			if atribute:GetAttribute("props1") == true then
				stop()
				atribute:SetAttribute("props1", false)
			atribute:SetAttribute("props2", true)
			end
		end)

		nextt.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("props1") == true then
				stop()
				atribute:SetAttribute("props1", false)
				atribute:SetAttribute("props2", true)
			end
		end)
		
		back.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("props1") == true then
				stop()
				atribute:SetAttribute("props1", false)
				atribute:SetAttribute("navigation", true)
			end
		end)

		back.Visible = true
		nextt.Visible = true
		prompt.Visible = true
		title = "properties"
		img = ""
		text = "now lets we modify some properties navigate to the gearwheele on the topbar (new ui) of the instance card and click them you (soon) also can change some propertes on the card"
	end
end

local function props2()
	if atribute:GetAttribute("props2") == true then

		PFmain.uidragdetector.scroller.badata.top.tooltip.ToolTip.Visible = true -- soon change
	
		PFmain.uidragdetector.scroller.badata.top.dropdown.MouseButton1Click:Connect(function() -- soon change
			if atribute:GetAttribute("props2") == true then
				stop()
				atribute:SetAttribute("props2", false)
				atribute:SetAttribute("props3", true)
			end
		end)

		nextt.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("props2") == true then
				stop()
				atribute:SetAttribute("props2", false)
				atribute:SetAttribute("props3", true)
			end
		end)

		back.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("props2") == true then
				stop()
				atribute:SetAttribute("props2", false)
				atribute:SetAttribute("props1", true)
			end
		end)

		back.Visible = true
		nextt.Visible = true
		prompt.Visible = true
		title = "properties"
		img = ""
		text = "nice you clicked the button  for now temporaly the example is on the ui dragdetector cuz the frame doesnt have the new ui but btw click the arrow on the properties group to calopase it <br></br><br></br> (if you clicked anothe gearwheele no wories it isnt (probably (if you folow the tutorial)) a bug its the tutorial what brings you here)" -- soon change
		
		for i,v in PFmain:GetChildren() do
			if v:IsA("Frame") then
				v.Visible = false

				PFmain.uidragdetector.Visible = true -- change soon
			end
		end	
	end
end

local function props3()
	if atribute:GetAttribute("props3") == true then
		
		PFmain.uidragdetector.scroller.cbehaviorpropperties.properties.enabled.BackgroundTransparency = 0 --change soon
		
		PFmain.uidragdetector.scroller.cbehaviorpropperties.properties.enabled.tooltip.ToolTip.Visible = true -- soon change

		PFmain.uidragdetector.scroller.cbehaviorpropperties.properties.enabled.checkmark.MouseButton1Click:Connect(function() -- soon change
			if atribute:GetAttribute("props3") == true then
				stop()
				atribute:SetAttribute("props3", false) -- curent
				atribute:SetAttribute("closeprops", true) -- next
			end
		end)

		nextt.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("props3") == true then
				stop()
				atribute:SetAttribute("props3", false) -- curent
				atribute:SetAttribute("closeprops", true) -- next
			end
		end)

		back.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("props3") == true then
				stop()
				atribute:SetAttribute("props3", false) -- curent
				atribute:SetAttribute("props2", true) -- previous
			end
		end)

		back.Visible = true
		nextt.Visible = true
		prompt.Visible = true
		title = "properties"
		img = ""
		text = "nice you did calopase the group now we have here some properties you can change like in the normal properties window make sure to click save to directly save or wait for the data save interval <br></br><br></br> well click the enabled propertie and disable it" -- soon change
	
		for i,v in PFmain:GetChildren() do
			if v:IsA("Frame") then
				v.Visible = false

				PFmain.uidragdetector.Visible = true -- change soon
			end
		end
	end
end

local function closeprops()
	if atribute:GetAttribute("closeprops") == true then

		PFmain.uidragdetector.top.tooltip.ToolTip.Visible = true -- soon change

		PFmain.uidragdetector.top.close.MouseButton1Click:Connect(function() -- soon change
			if atribute:GetAttribute("closeprops") == true then
				stop()
				atribute:SetAttribute("closeprops", false) -- curent
				atribute:SetAttribute("insert", true) -- next
				atribute:SetAttribute("insert1st" , true)
			end
		end)

		nextt.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("closeprops") == true then
				stop()
				atribute:SetAttribute("closeprops", false) -- curent
				atribute:SetAttribute("insert", true) -- next
				atribute:SetAttribute("insert1st" , true)
			end
		end)

		back.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("closeprops") == true then
				stop()
				atribute:SetAttribute("closeprops", false) -- curent
				atribute:SetAttribute("props3", true) -- previous
			end
		end)

		back.Visible = true
		nextt.Visible = true
		prompt.Visible = true
		title = "properties"
		img = ""
		text = "nice you toggled the enabled property now lets close this frame (soon you can dock this frame) with the close button " -- soon change

		for i,v in PFmain:GetChildren() do
			if v:IsA("Frame") then
				v.Visible = false

				PFmain.uidragdetector.Visible = true -- change soon
			end
		end	
	end
end

local function insert()
	if atribute:GetAttribute("insert") == true then
		
		main.guis.ascrennui.tooltip.ToolTip.Visible = true -- soon change
	
		main.guis.ascrennui.insert.MouseButton1Click:Connect(function() -- soon change
			if atribute:GetAttribute("insert1st") == true then
				back.Visible = true
				nextt.Visible = true
				prompt.Visible = true
				title = "inserting the instance"
				img = ""
				text = "now lets we insert a ui dragdetector and see that enabled is changed to false" -- soon change
				atribute:SetAttribute("insert2nd", true)
				atribute:SetAttribute("insert1st", false)
				main.guis.ascrennui.tooltip.ToolTip.Visible = false -- soon change
				main.guis.aUidragdetector.title.tooltip2.ToolTip.Visible = true -- soon change
			end
		end)
		
		main.guis.aUidragdetector.title.cinsert.MouseButton1Click:Connect(function() -- soon change
			if atribute:GetAttribute("insert2nd") == true then
				stop()
				atribute:SetAttribute("insert", false) -- curent
				atribute:SetAttribute("insert2nd", false)
				atribute:SetAttribute("settings", true) -- next
				main.guis.aUidragdetector.title.tooltip2.ToolTip.Visible = false -- soon change
			end
		end)

		nextt.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("insert") == true then
				stop()
				atribute:SetAttribute("insert", false) -- curent
				atribute:SetAttribute("insert1st", false)
				atribute:SetAttribute("insert2nd", false)
				atribute:SetAttribute("settings", true) -- next
			end
		end)

		back.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("insert") == true then
				stop()
				atribute:SetAttribute("insert", false) -- curent
				atribute:SetAttribute("insert1st", false)
				atribute:SetAttribute("insert2nd", false)
				atribute:SetAttribute("closeprops", true) -- previous
			end
		end)

		back.Visible = true
		nextt.Visible = true
		prompt.Visible = true
		title = "inserting the instance"
		img = ""
		text = "alrigt insert a screengui first and add a ui drag detector to it (soon a frame but you know the new ui doesnt aply on that)" -- soon change

		for i,v in main.guis:GetChildren() do
			if v:IsA("Frame") or v:IsA("CanvasGroup") then
				v.Visible = false
				main.guis.aUidragdetector.Visible = true
				main.guis.ascrennui.Visible = true
			end
		end	

	end
end

local function settingss()
	if atribute:GetAttribute("settings") == true then
		main.aTabs.settings.Tooltip.Visible = true
		
		main.aTabs.settings.MouseButton1Click:Connect(function() 
			if atribute:GetAttribute("settings") == true then
				stop()
			atribute:SetAttribute("settings", false)
			atribute:SetAttribute("dropdown1", true)
			end
		end)

		nextt.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("settings") == true then
				stop()
				atribute:SetAttribute("settings", false)
				atribute:SetAttribute("dropdown1", true)
			end
		end)
		
		back.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("settings") == true then
				stop()
				atribute:SetAttribute("settings", false) -- curent
				atribute:SetAttribute("insert", true) -- previous
			end
		end)

		back.Visible = true
		nextt.Visible = true
		prompt.Visible = true
		title = "settings"
		img = ""
		text = "i want to show you somthing else navigate to the settings i show you a setting for example"
		
		for i,v in main.guis:GetChildren() do
			if v:IsA("Frame") or v:IsA("CanvasGroup") then
				v.Visible = true
			end
		end	

	end
end

local function dropdown1()
	if atribute:GetAttribute("dropdown1") == true then
		main.btopbar.content.aselectsettings.tooltip.ToolTip.Visible = true

		main.btopbar.content.aselectsettings.dropf.dropd.styles.MouseButton1Click:Connect(function() 
			if atribute:GetAttribute("dropdown1") == true then
				stop()
				atribute:SetAttribute("dropdown1", false)
				atribute:SetAttribute("styles", true)
			end

		end)

		nextt.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("dropdown1") == true then

				stop()
				atribute:SetAttribute("dropdown1", false)
				atribute:SetAttribute("styles", true)
			end
		end)

		back.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("dropdown1") == true then
				stop()
				atribute:SetAttribute("dropdown1", false) -- curent
				atribute:SetAttribute("settings", true) -- previous
			end
		end)

		back.Visible = true
		nextt.Visible = true
		prompt.Visible = true
		title = "settings"
		img = ""
		text = "use the dropdown and select styles there also more settings you can acess them trough the dropdown like saving data go to styles now"
	end
end

local function styles()
	if atribute:GetAttribute("styles") == true then
		
		nextt.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("styles") == true then
				stop()
				atribute:SetAttribute("styles", false)
				atribute:SetAttribute("tools", true)
			end
		end)

		back.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("styles") == true then
				stop()
				atribute:SetAttribute("styles", false) -- curent
				atribute:SetAttribute("dropdown1", true) -- previous
			end
		end)

		back.Visible = true
		nextt.Visible = true
		prompt.Visible = true
		title = "settings"
		img = ""
		text = "congratulations you found the style settings on this way you can also navigate to other settings here can you change the dark mode or chose (soon) the secondary color"
	end
end

local function apps()
	if atribute:GetAttribute("tools") == true then
		main.aTabs.more.Tooltip.Visible = true

		main.aTabs.more.MouseButton1Click:Connect(function() 
			if atribute:GetAttribute("tools") == true then
				stop()
				atribute:SetAttribute("tools", false)
				atribute:SetAttribute("feedback", true)
			end

		end)

		nextt.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("tools") == true then
				stop()
				atribute:SetAttribute("tools", false)
				atribute:SetAttribute("feedback", true)
			end
		end)

		back.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("tools") == true then
				stop()
				atribute:SetAttribute("tools", false) -- curent
				atribute:SetAttribute("styles", true) -- previous
			end
		end)

		back.Visible = true
		nextt.Visible = true
		prompt.Visible = true
		title = "tools / apps"
		img = ""
		text = "alright now go to the topbar and select the four sqaures to go to apps"
	end
end

local function feedback()
	if atribute:GetAttribute("feedback") == true then
		main.more.apps.grid.tooltip.ToolTip.Visible = true

		main.more.apps.grid.feedback.MouseButton1Click:Connect(function() 
			if atribute:GetAttribute("feedback") == true then
				stop()
				atribute:SetAttribute("feedback", false)
				atribute:SetAttribute("end", true)
			end

		end)

		nextt.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("feedback") == true then
				stop()
				atribute:SetAttribute("feedback", false)
				atribute:SetAttribute("end", true)
			end
		end)

		back.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("feedback") == true then
				stop()
				atribute:SetAttribute("feedback", false) -- curent
				atribute:SetAttribute("tools", true) -- previous
			end
		end)

		back.Visible = true
		nextt.Visible = true
		prompt.Visible = true
		title = "apps | feedback"
		img = ""
		text = "good you found the apps pro users can use more extra apps (you can in that app follow a tutorial if you want) you find them here (soon you find here also betas) <br></br><br></br> alright for example lets we go to the feedback app"
	end
end

local function endd()
	if atribute:GetAttribute("end") == true then
		
		nextt.MouseButton1Click:Connect(function()
			if atribute:GetAttribute("end") == true then
				stop()
				atribute:SetAttribute("end", false)
			end
		end)

		back.Visible = true
		nextt.Visible = true
		prompt.Visible = true
		title = "feedback | end"
		img = ""
		text = "good you found the feedback app you can here also use the dropdown if i told to select feedback or bug report <br></br><br></br> well we now at the end of the tutorial remember explore the settings to customize the plugin and go to the feedback app to report any bugs and give your feedback good luck with the plugin your developer life will be easier"
	end
end

local function CT()
	if atribute:GetAttribute("end") == true then
	nextt.Text = "close"
elseif atribute:GetAttribute("end") == false then
	nextt.Text = "next"
end	
end

local function check()
	if atribute:GetAttribute("props2") == true then
		props2()
	end
end

local function cancel()
	task.wait(6)
	if atribute:GetAttribute("navigation") == true then
		navigation1()
	elseif atribute:GetAttribute("props1") == true then
		props1()
		text.Active = false
	elseif atribute:GetAttribute("props2") == true then
		props2()
		text.Active = false
	elseif atribute:GetAttribute("props3") == true then
		props3()
		text.Active = false
	elseif atribute:GetAttribute("closeprops") == true then
		closeprops()
		text.Active = false
	elseif atribute:GetAttribute("insert") == true then
		insert()
		text.Active = false
	elseif atribute:GetAttribute("settings") == true then
		settingss()
	elseif atribute:GetAttribute("dropdown1") == true then
		dropdown1()
		text.Active = false
	elseif atribute:GetAttribute("styles") == true then
		styles()
		text.Active = false
	elseif atribute:GetAttribute("tools") == true then
		apps()
		text.Active = false
	elseif atribute:GetAttribute("feedback") == true then
		feedback()
		text.Active = false
	elseif atribute:GetAttribute("end") == true then
		endd()
		text.Active = false
	end
end

local function closee()
	text ="clossing tutorial click once to cancel... (5)"
	task.wait(1)
	text ="clossing tutorial click once to cancel... (4)"
	task.wait(1)
	text ="clossing tutorial click once to cancel... (3)"
	task.wait(1)
	text ="clossing tutorial click once to cancel... (2)"
	task.wait(1)
	text ="clossing tutorial... (1)"
	text.Active = false
	task.wait(1)
	text ="clossing tutorial... (0)"
	for i,v in main.guis:GetChildren() do
		if v:IsA("Frame") or v:IsA("CanvasGroup") then
			v.Visible = true
		end
	end	
end

local function sure()
	text = "are you sure you want to leave the tutorial double click to leave the tutorial on this text to cancel click once"
	text.Active = true
end

atribute:GetAttributeChangedSignal("navigation"):Connect(navigation1)
atribute:GetAttributeChangedSignal("props1"):Connect(props1)
atribute:GetAttributeChangedSignal("props2"):Connect(props2)
PFmain.Parent:GetPropertyChangedSignal("Enabled"):Connect(check)
atribute:GetAttributeChangedSignal("props3"):Connect(props3)
atribute:GetAttributeChangedSignal("closeprops"):Connect(closeprops)
atribute:GetAttributeChangedSignal("insert"):Connect(insert)
atribute:GetAttributeChangedSignal("settings"):Connect(settingss)
atribute:GetAttributeChangedSignal("dropdown1"):Connect(dropdown1)
atribute:GetAttributeChangedSignal("styles"):Connect(styles)
atribute:GetAttributeChangedSignal("tools"):Connect(apps)
atribute:GetAttributeChangedSignal("feedback"):Connect(feedback)
atribute:GetAttributeChangedSignal("end"):Connect(endd)

CT() 

close.MouseButton1Click:Connect(sure)
text.MouseButton1Click:Connect(cancel)
text.MouseButton2Click:Connect(closee) --620 new record

how can i make this 560 lines of code more cliener it is to much to do but its beter than 1000 scripts

1 Like

you seem to have a lot of repeating stuff, why don’t you used tables/buffer with for loops?