Making the code shorter

Hello, me again,
As you can see, the code is like 100 lines long
How can I shorten this
This is for a plugin

local squip = Instance.new("Script") 
			squip.Source = [[--Instructions, replace 1 with your own badge ID
local badgeID = 0
local badgeService = game:GetService("BadgeService")
 
game.Players.PlayerAdded:Connect(function(player)
 wait(1)
 if not badgeService:UserHasBadge(player.UserId, badgeID) then
  badgeService:AwardBadge(player.UserId, badgeID)
 end
end)
]]
		
			squip.Parent = game.Workspace
			
		game.CoreGui:WaitForChild("UI").ImageLabel.Time.MouseButton1Click:connect(function() -- you will have to change Bar.Button to your ui names in the UI.
				local squip2 = Instance.new("Script") 
				squip2.Source = [[--Instructions, replace 0 with your own badge ID and change time to whatever you want, it`s in seconds
local badgeID = 0
local badgeService = game:GetService("BadgeService")

game.Players.PlayerAdded:Connect(function(player)
 wait(600)
 if not badgeService:UserHasBadge(player.UserId, badgeID) then
  badgeService:AwardBadge(player.UserId, badgeID)
 end
end)
]]
				squip2.Parent = game.Workspace
				
				game.CoreGui:WaitForChild("UI").ImageLabel.Touch.MouseButton1Click:connect(function() -- you will have to change Bar.Button to your ui names in the UI.
					local squip3 = Instance.new("Script") 
					squip3.Source = [[--Instructions, replace 0 with your own badge ID and place this into a part
local badgeservice = game:GetService("BadgeService")
local id = 0

script.Parent.Touched:Connect(function(hit)
 if hit.Parent:FindFirstChild("Humanoid") then
  local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
  badgeservice:AwardBadge(plr.UserId, id)
 end
end)
]]
					squip3.Parent = game.Workspace
					game.CoreGui:WaitForChild("UI").ImageLabel.Leaderstats.MouseButton1Click:connect(function() -- you will have to change Bar.Button to your ui names in the UI.
						local squip4 = Instance.new("Script") 
						squip4.Source = [[--Instructions, replace 0 with your own badge ID, change 100 to whatever amount you need and change Coins to your leaderstat value
local BadgeService = game:GetService("BadgeService")
local BadgeID = 0
local AmountNeeded = 100

game.Players.PlayerAdded:Connect(function(Player)
    Player.leaderstats.Coins.Changed:Connect(function()
     if Player.leaderstats.Coins.Value >= AmountNeeded then
       BadgeService:AwardBadge(Player.UserId, BadgeID)
   end
 end)
end)
]]
						squip4.Parent = game.Workspace
						game.CoreGui:WaitForChild("UI").ImageLabel.Meet.MouseButton1Click:connect(function() -- you will have to change Bar.Button to your ui names in the UI.
							local squip5 = Instance.new("Script") 
							squip5.Source = [[--Instructions, replace 0 with your own badge ID and replace Username with your own username
local BadgeID = 0

game.Players.PlayerAdded:Connect(function(Player)
	if game.Players:FindFirstChild("Username") then 
		for i, players in pairs(game.Players:GetPlayers())do 
			game.BadgeService:AwardBadge(players.UserId, BadgeID)
		end
	  end
	end)
]]
							squip5.Parent = game.Workspace
							game.CoreGui:WaitForChild("UI").ImageLabel.GiveTool.MouseButton1Click:connect(function() 
								local squip6 = Instance.new("Script") 
								squip6.Source = [[--Instructions, replace 0 with your own badge ID then put a tool in ReplicatedStorage and replace :WaitForChild("Tool") with :WaitForChild("the tool name")
local BadgeService = game:GetService("BadgeService")
local Tool = game:GetService("ReplicatedStorage"):WaitForChild("Tool")
local BadgeId = 0

game.Players.PlayerAdded:Connect(function(player)
	if BadgeService:UserHasBadgeAsync(player.UserId,BadgeId) then
		Tool:Clone().Parent = player.Backpack
		Tool:Clone().Parent = player.StarterGear
	end
end)
]]
								squip6.Parent = game.Workspace	
								
		end)
		
		end)
							
		end)
					
		end)
						
		end)
			
		end)
		
	else
		
		game.CoreGui:WaitForChild("UI").Parent = script -- hides the UI
		
	end
	
end)
2 Likes

Firstly, always format your code nicely (manually or with a formatter). Secondly, use better-named variables; I don’t understand what squip, squip2, etc are.

Beyond that, your templates for the generated scripts are long. Typically, one should move them into their constant variables. But, since they’re so long, I would move them into their modules and then require those modules.

local squipSource = require(script.squipSource)
local squipSource2 = require(script.squipSource2)
-- ...

local squip = Instance.new("Script")
squip.Source = squipSource
-- ...

Like that!

1 Like

Gee thanks, I kinda solved it myself already, and I dont really know how to close a topic

But you did what I did, so have a solution

No worries. While you can’t close a topic, you can always post your solution and mark it solved. That way, in case anyone else comes by with a similar problem–it’s already solved!

2 Likes