I am making a radar for CUBED Development and I thought this code would work in theory, but I seem to have messed up in some Gui thing I suspect. Please may you help me in fixing this broken code.

error: https://gyazo.com/dd3030836da3315651234e30f137c876

Thank you in advance.

Local Script in Gui: https://gyazo.com/391a84e7905f31dc7c89adbe03adcfbf

local scale = 4

local player = game.Players.LocalPlayer
local track = game.Workspace:WaitForChild("Radar")
local parts = {}

local maxDistance = 145/scale

function createBlip()
	local gui = script.Parent.player:Clone()
	gui.Parent = script.Parent:WaitForChild("blips")
	gui.BackgroundColor3 = Color3.new(1,0,0) -- or Color3.new(255,0,0)
	gui.BorderColor3 = Color3.new(1,0,0) -- or Color3.new(255,0,0)
	return gui
end

for i,v in pairs(track:GetChildren()) do
	if v:IsA("BasePart") then
		local gui = createBlip()
		table.insert(parts,{v,gui})
	elseif v:IsA("Model") and v:FindFirstChild("HumanoidRootPart") and player.Character == v then
		local gui = createBlip()
		table.insert(parts,{v,gui})
	end
end

track.ChildAdded:connect(function(child)
	if child:IsA("BasePart") then
		local gui = createBlip()
		table.insert(parts,{child,gui})
	elseif child:IsA("Model") and child:FindFirstChild("HumanoidRootPart") and player.Character ~= child then
		local gui = createBlip()
		table.insert(parts,{child.HumanoidRootPart,gui})
	end
end)

track.ChildRemoved:connect(function(child)
	local parts = {}
	for i,v in pairs(script.Parent.blips:GetChildren()) do
		v:Destroy()
	end
		for i,v in pairs(track:GetChildren()) do
		if v:IsA("BasePart") then
			local gui = createBlip()
			table.insert(parts,{v,gui})
		elseif v:IsA("Model") and v:FindFirstChild("HumanoidRootPart") and player.Character ~= v then
			local gui = createBlip()
			table.insert(parts,{v.HumanoidRootPart,gui})
		end
	end
end)

game:GetService("RunService").RenderStepped:connect(function()
	if player.Character then
		local posX = player.Character.HumanoidRootPart.CFrame.X
		local posZ = player.Character.HumanoidRootPart.CFrame.Z
		local direction = game.Workspace.CurrentCamera.CFrame.lookVector
		local heading = math.atan2(direction.x,direction.z)
		heading = math.deg(heading)+180
		script.Parent.blips.Rotation = heading
		for i = 1,#parts do
			local part = parts[i][1]
			local gui = parts[i][2]
			
			local difX = part.CFrame.X-posX
			local difZ = part.CFrame.Z-posZ
			
			local partDirection = part.CFrame.lookVector
			local partHeading = math.atan2(partDirection.x,partDirection.z)
			partHeading = -math.deg(partHeading)
			
			gui.BackgroundTransparency = ((player.Character.Torso.CFrame.p-parts[i][1].CFrame.p).magnitude-maxDistance)/10
			gui.Position = UDim2.new(0,70-difX*0.4*scale,0,70*0.4*scale)
		end
	end
end)

Server script in Server Script Service

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		wait(1)
		character.Parent = game.Workspace:WaitForChild("Radar")
	end)
end)