Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

is there any way to automate this script with functions ?

Helo ? am a pretty new scripter and ? understand this is a crappy script as well But ? am just experimenting and trying to learn and ? dont want 1 million lines coppying this 18 times in total


local billboardgui = game:GetService("ServerStorage"):WaitForChild("BillboardGui")

player.CharacterAdded:Connect(function(character)
	if player.leaderstats.Rank.Value == 1 then
			local clonedgui = billboardgui:Clone()
			clonedgui.TextLabel.Text = "Private"
			clonedgui.TextLabel.TextColor3 = Color3.fromRGB(28, 16, 186)
			clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head	
		else
	if player.leaderstats.Rank.Value == 2 then
			local clonedgui = billboardgui:Clone()
			clonedgui.TextLabel.Text = "Private First class"
			clonedgui.TextLabel.TextColor3 = Color3.fromRGB(28, 16, 186)
			clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head

i am yet working on the script and ? just need a fast way to copy these

1 answer

✓ Accepted answer

Your question is pretty vague, but I think what you are trying to do change the text of the clonedgui for each rank. The way to do this is pretty easy

local function CreateRankGui(rankText) 
	if player:IsInGroup(2870505) then
           local clonedgui = billboardgui:Clone()
	   clonedgui.TextLabel.Text = rankText
	   clonedgui.TextLabel.TextColor3 = Color3.fromRGB(28, 16, 186)
	   clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head
	 end
end

You would put this function at the start of your script, after you define your variables. Then, in your PlayerAdded event, you would keep the if statements for the rank and just insert the function in place of the identical blocks of code:

player.CharacterAdded:Connect(function(character)
	    if player.leaderstats.Rank.Value == 1 then
		CreateRankGui("Private")
	    else if player.leaderstats.Rank.Value == 2 then
	 	CreateRankGui("Private First Class")                   
	     end
	 
end)

And then you would just continue the trend with more "else if" statements and different ranks

This discussion is preserved as it was. New answers, comments, and votes are closed.