How to recreate script?

I need recreate script - current player rank - Here has " GUI Group Rank name Display or Leaderstats GUI"
Ik its easy to remake this script for better, i no has ideas how do that.
so
I need remake this script for current player group rank

    1. Current player rank at text label - text need switching if player rank like - General
    1. If player not in group he get “Citizen” rank
    1. script what need remaked
groupid = 861664
game.Players.PlayerAdded:connect(onPlayerRespawned)
function onPlayerRespawned(newPlayer)
	wait(0.5)
	local gui = script.Parent.Parent.Parent.Parent.PlayerStatsGui:Clone()
	local texta=gui.Frame.CurrentRank
	texta.Text = (newPlayer:GetRoleInGroup(groupid))
	texta.TextColor3 = Color3.new(255,255,255)
	texta.TextStrokeColor3 = Color3.new(255,255,255)
	wait(1)
end

(sorry for bad english )