Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

is there any way to automate this script with functions ?

Asked by
gjlkv1 11
5 years ago
Edited 5 years ago

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

01local billboardgui = game:GetService("ServerStorage"):WaitForChild("BillboardGui")
02 
03player.CharacterAdded:Connect(function(character)
04    if player.leaderstats.Rank.Value == 1 then
05            local clonedgui = billboardgui:Clone()
06            clonedgui.TextLabel.Text = "Private"
07            clonedgui.TextLabel.TextColor3 = Color3.fromRGB(28, 16, 186)
08            clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head   
09        else
10    if player.leaderstats.Rank.Value == 2 then
11            local clonedgui = billboardgui:Clone()
12            clonedgui.TextLabel.Text = "Private First class"
13            clonedgui.TextLabel.TextColor3 = Color3.fromRGB(28, 16, 186)
14            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

Log in to vote
0
Answered by 5 years ago

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

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

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:

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

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

Ad

Answer this question