Can someone fix my script?

Hi,I am trying to script my player list but I have no idea why my script bug.


local PlayerListRemoteEvent = game.ReplicatedStorage:WaitForChild("Player")
local Player = game.Players.LocalPlayer
local LocalPlayerList = {}
local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(0.5,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut)

local function Refresh()
	for i,v in pairs(script.Parent:GetChildren()) do
	if v.Name ~= "FrameReferesh" or v.Name ~= "PLAYERFRAME" then
		v:Destroy()
	end
end
for i,v in pairs(LocalPlayerList) do
	local Framedd = script.Parent
	local NewFrame = Framedd.PLAYERFRAME:Clone()
	NewFrame.Parent = script.Parent
	NewFrame.Name = v.Name
	NewFrame.Player.Text = v.Name
	if i == 1 then
		NewFrame.Position = UDim2.new(0.5,0,0.01,0)
	else
		local NewI = i - 1
		local Mix = 0.02 * NewI
		NewFrame.Position = UDim2.new(0.5,0,0.01+Mix,0)
	end
end
end

for i,v in pairs(game.Players:GetChildren()) do
if v ~= Player then
	table.insert(LocalPlayerList,1,v)
	Refresh()
    end
 end

PlayerListRemoteEvent.OnClientEvent:Connect(function(Plr)
if Player ~= Plr then
	Refresh()
end
end)

This is going too over the top. All you need is a UIListLayout, like shown

local Players = game:GetService("Players")
locla mainFrame = script.Parent

for i, v in pairs(Players:GetChildren()) do
    local playerBox = script.playerBox:Clone()
    playerBox.Parent = mainFrame
    playerBox.Text = v.Name
end

The UIListLayout automatically sorts the playerlist into an actual list.

I hope to have an animation for my UI so that I can make my game being perfect.