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
4 years ago
Edited 4 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


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

Log in to vote
0
Answered by 4 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

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

Ad

Answer this question